import javax.inject.Inject;
import javax.inject.Singleton;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/add")
@Singleton
public class CounterController {
private final CounterService counterService;
// Resteasy/CDI requires @Context+@Singleton for constructor injection to work
// https://issues.jboss.org/browse/RESTEASY-1538
// http://stackoverflow.com/a/33658338/365237
@Inject
public CounterController(@Context CounterService counterService) {
this.counterService = counterService;
}
@POST
public void add(@Suspended final AsyncResponse asyncResponse, @Valid
CounterRequest counterRequest) {
asyncResponse.resume(counterService.count(counterRequest));
}
}
和
import javax.ejb.Asynchronous;
import javax.ejb.Stateless;
@Stateless
@Asynchronous
public class CounterService {
public CounterResult count(CounterRequest counterRequest) {
return new CounterResult(
counterRequest.getInt1() + counterRequest.getInt2());
}
}
如果我使用wildfly版本2018.3.0,工作正常,但如果我使用2018.4.0或2018.5.0,我会
2018-06-08 23:14:30,898 ERROR [stderr] (main) Exception in thread "main" java.lang.reflect.InvocationTargetException
2018-06-08 23:14:30,898 ERROR [stderr] (main) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2018-06-08 23:14:30,898 ERROR [stderr] (main) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2018-06-08 23:14:30,898 ERROR [stderr] (main) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2018-06-08 23:14:30,898 ERROR [stderr] (main) at java.lang.reflect.Method.invoke(Method.java:497)
2018-06-08 23:14:30,898 ERROR [stderr] (main) at org.wildfly.swarm.bootstrap.MainInvoker.invoke(MainInvoker.java:53)
2018-06-08 23:14:30,898 ERROR [stderr] (main) at org.wildfly.swarm.bootstrap.MainInvoker.main(MainInvoker.java:106)
2018-06-08 23:14:30,898 ERROR [stderr] (main) Caused by: org.wildfly.swarm.container.DeploymentException: org.wildfly.swarm.container.DeploymentException: WFSWARM0004: Deployment failed: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"wildfly-swarm-example-1.0-SNAPSHOT.war\".WeldStartService" => "Failed to start service
2018-06-08 23:14:30,898 ERROR [stderr] (main) Caused by: org.jboss.weld.exceptions.DeploymentException: Exception List with 5 exceptions:
2018-06-08 23:14:30,898 ERROR [stderr] (main) Exception 0 :
2018-06-08 23:14:30,898 ERROR [stderr] (main) org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type DeploymentContext with qualifiers @Default
2018-06-08 23:14:30,898 ERROR [stderr] (main) at injection point [BackedAnnotatedField] @Inject org.wildfly.swarm.container.runtime.cdi.configurable.DeploymentProducer.context
2018-06-08 23:14:30,900 ERROR [stderr] (main) Exception 2 :
2018-06-08 23:14:30,900 ERROR [stderr] (main) org.jboss.weld.exceptions.DeploymentException: WELD-001410: The injection point has non-proxyable dependencies: [BackedAnnotatedField] @Inject private org.wildfly.swarm.container.runtime.RuntimeDeployer.defaultDeploymentCreator
2018-06-08 23:14:30,901 ERROR [stderr] (main) Caused by: org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001435: Normal scoped bean class org.wildfly.swarm.container.runtime.deployments.DefaultDeploymentCreator is not proxyable because it has no no-args constructor - Managed Bean [class org.wildfly.swarm.container.runtime.deployments.DefaultDeploymentCreator] with qualifiers [@Any @Default].
示例回购:working,non-working。
我确实有beans.xml作为
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
我正在使用mvn clean wildfly-swarm:run
。
关于事业的想法?这会是一个错误吗?我已经浏览了changelog并且没有看到与我相关的任何内容。默认情况下,只有破坏变化才会生成jax-rs Application类,但无论如何我都有这个类。