Getting error, not sure why since I'm using beans.xml
in both modules effected.
WELD-001408 Unsatisfied dependencies for type [String] with qualifiers [@SystemProperty] at injection point [[parameter 1] of [constructor] @Inject public com.comp.alert.EmailAlertHandler(String, String)]
SystemProperty.java:
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
public @interface SystemProperty {
@Nonbinding String value();
}
EmailAlertHandler.java (only included part of the code that uses @Systemproperty:
@Email
@Stateless
public class EmailAlertHandler implements AlertHandler {
@Inject
public EmailAlertHandler(@SystemProperty("min.email.from") String emailFrom,
@SystemProperty("min.email.to") String emailTo) {
this.emailFrom = emailFrom;
this.emailTo = emailTo;
}
@Override
public void sendAlert(Alert alert) {
//body omitted
}
}
beans.xml that is defined in the module for EmailAlertHandler:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"/>
beans.xml that is definied in the module for SystemProperty:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"/>
EmailAlertHandler is injected here. The sendAlertAsync method being called in another class to essentially kick off the functionality:
@Singleton
@Startup
public class AlertManager {
@Inject @Email
private AlertHandler emailAlertHandler;
@Asynchronous
public void sendAlertAsync(Alert alert) {
// Handle alert via email
emailAlertHandler.sendAlert(alert);
}
}
Essentially all solutions I have already found on similar unsatisfied/missing dependency errors point to configuring beans.xml but that hasn't solved anything.
It looks like nothing produces these Strings.
Do you have producers?
You can try with:
public class PropertyProducer {
@Produces
public String createProperty(InjectionPoint injectionPoint) {
String value =injectionPoint.getAnnotation(SystemProperty.class).value();
return System.getProperty(value);
}
}