resteasy-cdi - 获取"重复上下文初始化参数resteasy.injector.factory"错误

dgi*_*nes 2 jboss jax-rs resteasy cdi

我需要在我正在使用RESTEASY的休息应用程序上使用CDI功能.所以我按照手册的说明在我的应用程序上设置了resteasy-cdi模块,该模块在JBoss AS7上运行.

但是当我启动服务器时,我收到以下错误:

13:48:08,631 ERROR [org.apache.catalina.core.StandardContext](MSC服务线程1-4)由于先前的错误,上下文[/ MainService]启动失败:java.lang.IllegalArgumentException:重复的上下文初始化参数resteasy.injector .厂

我的web.xml如下:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    <listener>
        <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
    </listener>
    <servlet>
        <servlet-name>Resteasy</servlet-name>
        <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    </servlet>
    <context-param>
        <param-name>resteasy.injector.factory</param-name>
        <param-value>org.jboss.resteasy.cdi.CdiInjectorFactory</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>
    </context-param>
    <servlet-mapping>
        <servlet-name>Resteasy</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

我已经尝试了几种参数组合,并尝试在此线程中配置它,但没有成功.

在web.xml上指定javax.ws.rs.core.Application并禁用resteasy.scan也无法解决问题.

我的pom.xml包含以下内容:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-cdi</artifactId>
    <version>2.2.1.GA</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用和不使用神器resteasy-jarxs进行测试,以及像本文一样的依赖声明.

我真的迷路了.你有什么想法?我现在需要CDI或EJB来通过注入使用JPA的EntityManager.我知道没有它我就可以使用,但我更愿意这样,我可以探索JTA的集成和CDI未来的功能.

谢谢.

小智 7

问题是AS7捆绑了resteasy-cdi,你也捆绑了它.AS7部署扫描程序从两个jar中拾取并处理Web片段,声明resteasy.injector.factory发出"重复"错误.您有两个选项,使用提供的resteasy版本(首选)或删除提供的模块.

对于第一个选项,您可以设置您提供的maven依赖关系,并在清单中添加对resteasy的依赖关系.要在最新版本的AS7上运行(从https://github.com/jbossas/jboss-as构建),尝试将配置更改为更像这样:

<properties>
    <resteasy.version>2.2.3.GA</resteasy.version>
    <maven.war.plugin.version>2.1.1</maven.war.plugin.version>
</properties>

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>${resteasy.version}</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-cdi</artifactId>
    <version>${resteasy.version}</version>
    <scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

并在清单中添加对resteasy-cdi的依赖,例如:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>${maven.war.plugin.version}</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <archive>
                    <manifestEntries>
                        <Dependencies>
                            org.jboss.resteasy.resteasy-jaxrs,
                            org.jboss.resteasy.resteasy-cdi
                        </Dependencies>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

查看$ JBOSS_HOME/modules/org/jboss/resteasy/...以了解您的AS7版本提供的resteasy版本.

或者,您可以从jboss中删除这些模块并继续捆绑您自己的副本.

有关更多详细信息,请参阅RESTEASY-586附带的破坏战争和固定战争的示例.