WELD-001409:带有限定符@Default的类型StepContext的不明确依赖关系

时间:2017-10-03 04:25:48

标签: java cdi weld jsr352 jberet

我正试图在我的Windows命令提示符下运行java SE模式中的this示例。我已经构建了一个包含所有依赖项的jar并从命令提示符运行它。

但是,不断出现this错误。从this answer开始,我知道在我的运行时类路径中可能有多个StepContext类。

我现在用maven-shade插件替换maven-assembly插件来构建我的胖罐,我可以在打包jar时看到以下警告

[WARNING] javax.inject-1.jar, weld-se-2.2.15.Final.jar define 6 overlapping classes: 
[WARNING] - javax.inject.Inject 
[WARNING] - javax.inject.Singleton 
[WARNING] - javax.inject.Scope 
[WARNING] - javax.inject.Named 
[WARNING] - javax.inject.Provider 
[WARNING] - javax.inject.Qualifier 

我将以下依赖项更新为已提供,现在我在打包时没有看到上述警告但是,在运行新生成的jar时仍然会出现异常

<dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
            <scope>provided</scope>
        </dependency>

执行JAR文件时的当前异常

Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type InjectionPoint with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Produces @BatchProperty public org.jberet.creation.BatchBeanProducer.getStringList(InjectionPoint)
  at org.jberet.creation.BatchBeanProducer.getStringList(BatchBeanProducer.java:0)
  Possible dependencies:
  - Implicit Bean [javax.enterprise.inject.spi.InjectionPoint] with qualifiers [@Default],
  - Managed Bean [class org.jboss.weld.manager.BeanManagerImpl$InstanceInjectionPoint] with qualifiers [@Any @Default],
  - Managed Bean [class org.jboss.weld.injection.EmptyInjectionPoint] with qualifiers [@Any @Default]

        at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:392)
        at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:294)
        at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:135)
        at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:168)
        at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:543)
        at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)
        at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)
        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type InjectionPoint with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Produces @BatchProperty public org.jberet.creation.BatchBeanProducer.getStringBuilder(InjectionPoint)
  at org.jberet.creation.BatchBeanProducer.getStringBuilder(BatchBeanProducer.java:0)
  Possible dependencies:
  - Implicit Bean [javax.enterprise.inject.spi.InjectionPoint] with qualifiers [@Default],
  - Managed Bean [class org.jboss.weld.manager.BeanManagerImpl$InstanceInjectionPoint] with qualifiers [@Any @Default],
  - Managed Bean [class org.jboss.weld.injection.EmptyInjectionPoint] with qualifiers [@Any @Default]

        at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:392)
        at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:294)
        at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:135)
        at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:168)
        at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:543)
        at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)
        at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)
        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

        at org.jboss.weld.bootstrap.ConcurrentValidator.validateBeans(ConcurrentValidator.java:76)
        at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:504)
        at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:435)
        at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)
        at org.jboss.weld.environment.se.Weld.initialize(Weld.java:148)
        at org.jberet.se.SEArtifactFactory.<init>(SEArtifactFactory.java:29)
        at org.jberet.se.BatchSEEnvironment.getArtifactFactory(BatchSEEnvironment.java:133)
        at org.jberet.operations.JobOperatorImpl.<init>(JobOperatorImpl.java:93)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        ... 8 more

如何解决此问题?

2 个答案:

答案 0 :(得分:0)

在我看来,你的扁平化会导致焊接实现最终出现在带有beans.xml的jar中,这会导致库的无意中部分由于bean的发现模式而显示为托管bean。所有& #34; (这也是没有版本的空beans.xml的情况)。

你应该尽量确保它的bean-discovery-mode =&#34;注释&#34;如果您要将焊接材料装入一个大罐子中,那么应用程序就可以了。

答案 1 :(得分:0)

最后能够使用JBERET实现在Java SE模式下运行Java批处理程序的可执行(胖)JAR。

This link提到了这一点,一旦我切换到2.4.5.Final它工作正常。

  

直到最近,嵌套/胖JAR才与Weld合作,直到在Weld 2.3.4中使用WELD-1930进行修复