GuiceResteasyBootstrapServletContextListener和CDI(WildFly 8.2.0.Final / RESTEasy 3.0.10.Final / Guice 3.0)

时间:2015-03-25 20:36:05

标签: cdi guice resteasy wildfly

我最近在Guice,CDI和RESTEasy方面遇到了困难。有没有人有这种困难的类似经验或好的解决方案?

上下文

我试图在RESTEasy(JAX-RS)应用程序中使用Guice来DI资源类。但是当我刚刚添加GuiceResteasyBootstrapServletContextListener时,它无法部署。

该项目有src / main / webapp / WEB-INF / beans.xml。添加它是为了使用其他工程师的一些与EJB相关的功能。删除beans.xml以进行试验会消除DeploymentException,但我无法将其从主干中删除。

这与Guava's past issue with CDI非常相似,但我不确定如何从RESTEasy的用户端处理它。 (我无法修改RESTEasy以在RESTEasy中添加' bean-discovery-mode =" none"'。

更新(2015年3月15日)

只使用带有beans.xml和javax.enterprise的@javax.ejb.Stateless:cdi-api会导致此问题。


请参阅下面的最低复制和错误信息。


的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>foo</groupId><artifactId>guice-cdi-test</artifactId>
  <version>1.0</version><packaging>war</packaging><name>Guice and CDI test</name>
  <dependencies>
    <!-- Enabling this cdi-api or creating src/main/webapp/WEB-INF/beans.xml will cause Weld's DeploymentException. -->
    <!--
    <dependency>
      <groupId>javax.enterprise</groupId><artifactId>cdi-api</artifactId>
      <version>1.2</version>
    </dependency>
    -->

    <dependency>
      <groupId>org.jboss.resteasy</groupId><artifactId>jaxrs-api</artifactId>
      <version>3.0.10.Final</version>
    </dependency>
    <dependency>
      <groupId>org.jboss.resteasy</groupId><artifactId>resteasy-guice</artifactId>
      <version>3.0.10.Final</version>
    </dependency>

    <dependency>
      <groupId>com.google.inject</groupId><artifactId>guice</artifactId>
      <version>3.0</version>
    </dependency>
  </dependencies>
</project>

的src /主/爪哇/ Application.java

@javax.ws.rs.ApplicationPath("/")
public class Application extends javax.ws.rs.core.Application {}

的src /主/ web应用/ WEB-INF / web.xml中

<web-app version="3.0" 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/web-app_3_0.xsd">
  <listener>
    <listener-class>org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>Resteasy</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Resteasy</servlet-name><url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

的src /主/ web应用/ WEB-INF / beans.xml中

(empty file)

错误消息(部署中)

20:19:49,332 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."guice-cdi-test-1.0.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."guice-cdi-test-1.0.war".WeldStartService: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_75]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_75]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_75]
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type Injector with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject private org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener.parentInjector
  at org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener.parentInjector(GuiceResteasyBootstrapServletContextListener.java:0)

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:372)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:293)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:134)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:167)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:531)
    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(FutureTask.java:262) [rt.jar:1.7.0_75]
    ... 3 more

0 个答案:

没有答案