Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带限定符@SystemProperty的类型字符串的未满足依赖项_Java_Maven_Jboss_Wildfly - Fatal编程技术网

Java 带限定符@SystemProperty的类型字符串的未满足依赖项

Java 带限定符@SystemProperty的类型字符串的未满足依赖项,java,maven,jboss,wildfly,Java,Maven,Jboss,Wildfly,我试图通过注入值来读取系统属性 我想作为参考 我的代码看起来像 @Qualifier @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) public @interface SystemProperty { /* Full name of System Property *

我试图通过注入值来读取
系统属性

我想作为参考

我的代码看起来像

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
public @interface SystemProperty {
    /*
    Full name of System Property
     */
    @Nonbinding
    String value();
}  

我注射的方式是

@Stateless
public class UniqueIdGenerator {
    private static final String COLON = ":";

    private String serverPrivateKey;

    @SuppressWarnings("UnusedDeclaration")
    public UniqueIdGenerator() {
    }

    @Inject
    public UniqueIdGenerator(@SystemProperty("com.kb.serverPrivateKey") @Nonnull final String serverPrivateKey) {
        this.serverPrivateKey = serverPrivateKey;
    }
    ....
}  
我使用
maven cargo
部署我的
war
,并将属性设置为

                 <container>
                    <containerId>wildfly8x</containerId>
                    <dependencies combine.children="append">
                        <dependency>
                            <groupId>com.h2database</groupId>
                            <artifactId>h2</artifactId>
                        </dependency>
                    </dependencies>
                    <systemProperties>
                        <com.kb.serverPrivateKey>test</com.kb.serverPrivateKey>
                    </systemProperties>
                </container>

我遗漏了什么?

通过日志中的以下消息:

[INFO] [talledLocalContainer] 11:57:49,676 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC000001: Failed to start service jboss.deployment.unit."application.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."application.war".WeldStartService: Failed to start service
EJB类中不会出现此错误,此消息是通过按类部署
application.war
模块
com.karmabeta.services.filter.AuthTokenValidatorFilter
生成的

根据文件信息:

WELD-001408: Unsatisfied dependencies for type String with qualifiers @SystemProperty
要修复未满足的依赖项,请执行以下任一操作:

  • 创建一个bean,它实现bean类型并具有注入点的所有限定符类型
  • 确保您已经拥有的bean位于具有注入点的模块的类路径中,或者
  • 使用beans.xml显式启用实现bean类型并具有适当限定符类型的
    @Alternative
    bean
  • 使用
    @Priority
    注释,启用一个实现bean类型并具有适当限定符类型的
    @Alternative
    bean
我认为第二项是解决方案的一部分,您可能在ejb模块中有生产者,这使得它在war模块中不可见

请注意,
@Producer
始终只能从顶级部署单元(例如war或ear/lib)获取,而不是从子部署获取

如果是这种情况,您可以将生产者和其他组件CDI放入ear/lib或直接war/classes中的jar文件中


我希望这有帮助。

假设您正在使用WildFly 8.x/CDI 1.1,您的
SystemPropertyProvider
似乎被忽略,因为它缺少一个bean定义注释。或者您是否使用合适的
beans.xml
描述符将其放入显式bean存档中


顺便说一句,对于注入系统和其他环境属性,我建议看一看ApacheDeltaspike。

这些类在不同的JAR中吗?这两个文件中都有beans.xml吗?
[INFO] [talledLocalContainer] 11:57:49,676 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC000001: Failed to start service jboss.deployment.unit."application.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."application.war".WeldStartService: Failed to start service
WELD-001408: Unsatisfied dependencies for type String with qualifiers @SystemProperty