字符串 jboss6 类型的未满足依赖项



收到错误,不知道为什么,因为我在两个模块中使用beans.xml都受到影响。

WELD-001408 在 [构造函数] 的注入点 [[参数 1] 处具有限定符 [@SystemProperty] 的类型 [String] 的未满足依赖项 @Inject public com.comp.alert.EmailAlertHandler(字符串、字符串(]

系统属性.java:

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
public @interface SystemProperty {
@Nonbinding String value();
}

EmailAlertHandler.java(仅包含使用@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 
}
}

bean.xml在 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"/>

bean.xml在 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 被注入到这里。在另一个类中调用的 sendAlertAsync 方法基本上启动了该功能:

@Singleton
@Startup
public class AlertManager {
@Inject @Email
private AlertHandler emailAlertHandler;
@Asynchronous
public void sendAlertAsync(Alert alert) {
// Handle alert via email
emailAlertHandler.sendAlert(alert);
}
}

基本上,我已经在类似的不满意/缺失的依赖项错误上找到的所有解决方案都指向配置 bean.xml但这并没有解决任何问题。

看起来没有什么东西会生成这些字符串。

你有制片人吗?

您可以尝试:

public class PropertyProducer {
@Produces
public String createProperty(InjectionPoint injectionPoint) {
String value =injectionPoint.getAnnotation(SystemProperty.class).value();
return System.getProperty(value);
}
}

最新更新