我在 CDI2.0 上使用 Wildfly Weld 进行 CDI 实现,使用 JavaSE 在 CDI2.0 上进行 POC。我能够使用 maven exec:java 命令运行应用程序。我添加了带有依赖插件的 maven 单个 jar 来制作带有 java 主类的单个 jar。取单个 jar 并执行 jar 也运行良好(java -jar appl*.jar)。
我使用 SmallRye 添加了 FaultTolerence ( Microprofile )。使用 maven exec:java 命令也可以很好地工作。但不能在 Jar 中工作,依赖项得到下面提到的错误。虽然我<exclude name="org.jboss.weld.**" />
在 beans.xml中添加了
如何解决这个问题?
我想要一个具有所有依赖项并且运行没有任何问题的 jar
项目在我的 git repo https://github.com/Gnanapandithan/standalone中可用
我已经关注了http://www.mastertheboss.com/jboss-frameworks/cdi/building-a-cdi-2-standalone-java-application这个并添加了 Faulttolerence(SmallRye),但没有工作。
@Asynchronous
@Retry(maxRetries = 2,retryOn = NullPointerException.class, delay = 200)
@Fallback(fallbackMethod = "sayHello")
public Future<String> greet() {
try {
System.out.println(" Greet ..................");
} catch (Exception e) {
e.printStackTrace();
}
String s = null;
s.length();
System.out.println("Hello World!");
return CompletableFuture.completedFuture("OK");
}
private Future<String> sayHello() {
System.out.println(" sayHello...");
return CompletableFuture.completedFuture( "I am from Hello..");
}
pom.xml
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0.SP1</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-shaded</artifactId>
<version>3.1.0.Beta1</version>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.fault-tolerance</groupId>
<artifactId>microprofile-fault-tolerance-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-fault-tolerance</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-config</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13-beta-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.demo.small.AppMain</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.demo.small.AppMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
例外:
INFO: WELD-001125: Illegal bean type rx.functions.Func1<java.util.List<? extends rx.Observable<?>>, rx.Observable<?>[]> ignored on [EnhancedAnnotatedTypeImpl] final static class rx.internal.util.InternalObservableUtils$ToArrayFunc1
Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: Exception List with 10 exceptions:
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 io.smallrye.config.inject.ConfigProducer.getConfig(InjectionPoint)
at io.smallrye.config.inject.ConfigProducer.getConfig(ConfigProducer.java:0)
Possible dependencies:
- Implicit Bean [javax.enterprise.inject.spi.InjectionPoint] with qualifiers [@Default],
- Managed Bean [class io.smallrye.config.inject.ConfigInjectionBean$InjectionPointMetadataInjectionPoint] with qualifiers [@Any @Default]
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:386)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:290)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:143)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:164)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:526)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:64)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:62)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
at org.jboss.weld.executor.CommonForkJoinPoolExecutorServices.lambda$wrap$0(CommonForkJoinPoolExecutorServices.java:70)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinTask.externalAwaitDone(ForkJoinTask.java:326)
at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:391)
at java.util.concurrent.ForkJoinTask.quietlyJoin(ForkJoinTask.java:1079)
at java.util.concurrent.ForkJoinPool.invokeAll(ForkJoinPool.java:2725)
at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:59)
at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:67)
at org.jboss.weld.bootstrap.ConcurrentValidator.validateBeans(ConcurrentValidator.java:62)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:487)
at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:490)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:93)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:804)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:176)
at com.demo.small.AppMain.main(AppMain.java:12)
Exception 1 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type InjectionPoint with qualifiers @Default
at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Dependent @Produces @ConfigProperty io.smallrye.config.inject.ConfigProducer.produceDoubleConfigProperty(InjectionPoint)
at io.smallrye.config.inject.ConfigProducer.produceDoubleConfigProperty(ConfigProducer.java:0)
Possible dependencies:
- Implicit Bean [javax.enterprise.inject.spi.InjectionPoint] with qualifiers [@Default],
- Managed Bean [class io.smallrye.config.inject.ConfigInjectionBean$InjectionPointMetadataInjectionPoint] with qualifiers [@Any @Default]
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:386)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:290)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:143)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:164)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:526)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:64)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:62)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
at org.jboss.weld.executor.CommonForkJoinPoolExecutorServices.lambda$wrap$0(CommonForkJoinPoolExecutorServices.java:70)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinTask.externalAwaitDone(ForkJoinTask.java:326)
at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:391)
at java.util.concurrent.ForkJoinTask.quietlyJoin(ForkJoinTask.java:1079)
at java.util.concurrent.ForkJoinPool.invokeAll(ForkJoinPool.java:2725)
at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:59)
at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:67)
at org.jboss.weld.bootstrap.ConcurrentValidator.validateBeans(ConcurrentValidator.java:62)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:487)
at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:490)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:93)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:804)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:176)
at com.demo.small.AppMain.main(AppMain.java:12)
Exception 2 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type InjectionPoint with qualifiers @Default
at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Dependent @Produces @ConfigProperty io.smallrye.config.inject.ConfigProducer.produceBooleanConfigProperty(InjectionPoint)
at io.smallrye.config.inject.ConfigProducer.produceBooleanConfigProperty(ConfigProducer.java:0)
Possible dependencies:
- Implicit Bean [javax.enterprise.inject.spi.InjectionPoint] with qualifiers [@Default],
- Managed Bean [class io.smallrye.config.inject.ConfigInjectionBean$InjectionPointMetadataInjectionPoint] with qualifiers [@Any @Default]
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:386)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:290)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:143)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:164)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:526)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:64)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:62)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
at org.jboss.weld.executor.CommonForkJoinPoolExecutorServices.lambda$wrap$0(CommonForkJoinPoolExecutorServices.java:70)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinTask.externalAwaitDone(ForkJoinTask.java:326)
at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:391)
at java.util.concurrent.ForkJoinTask.quietlyJoin(ForkJoinTask.java:1079)
at java.util.concurrent.ForkJoinPool.invokeAll(ForkJoinPool.java:2725)
at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:59)
at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:67)
at org.jboss.weld.bootstrap.ConcurrentValidator.validateBeans(ConcurrentValidator.java:62)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:487)
at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:490)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:93)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:804)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:176)
at com.demo.small.AppMain.main(AppMain.java:12)