开发者

resteasy-cdi - getting "Duplicate context initialization parameter resteasy.injector.factory" error

I'm needing CDI functionality on a rest application in which I'm using RESTEASY. So I followed the manual's instruction to setup resteasy-cdi module on my app, that runs on JBoss AS7.

But when I start the server I get the following error:

13:48:08,631 ERROR [org.a开发者_运维问答pache.catalina.core.StandardContext] (MSC service thread 1-4) Context [/MainService] startup failed due to previous errors: java.lang.IllegalArgumentException: Duplicate context initialization parameter resteasy.injector.factory

My web.xml is the following:

<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>

I've tried several combinations of parameters, and tried to configure it like in this thread also, but without success.

Specifying the javax.ws.rs.core.Application on the web.xml and desabling the resteasy.scan also didn't solve the problem.

My pom.xml has the following content:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-cdi</artifactId>
    <version>2.2.1.GA</version>
</dependency>

I've also tried testing with and without the artifact resteasy-jarxs together and with the declaration of the dependency like this article.

I'm really lost. Do you have any ideas? I need CDI or EJB for now to use JPA's EntityManager via injection. I know that I can use without it, but I'd prefer to so I can explore JTA's integration and CDI's functionality on the future.

Thanks.


The problem is that AS7 bundles resteasy-cdi and you are also bundling it. The AS7 deployment scanner picks up and processes the web-fragments from both jars which declare resteasy.injector.factory giving the 'duplicate' error. You have two options, use the provided version of resteasy (preferred) or remove the provided module.

For the first option you set set your maven dependency as provided and add a dependency on resteasy in your manifest. To run on the latest version of AS7 (build from https://github.com/jbossas/jboss-as) try changing your config to look more like this:

<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>

And add a dependency on resteasy-cdi in your manifest, e.g.:

<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>

Have a look in $JBOSS_HOME/modules/org/jboss/resteasy/... to find out which version of resteasy is provided by your version of AS7.

Alternatively you can remove these modules from jboss and proceed bundling your own copy.

See the examples of a broken war and fixed war attached to RESTEASY-586 for more details.


I hit this same error, experimented with RestEasy jar versions and inclusion/exclusion, and made no progress solving it. So I reported a bug at the RestEasy JBoss issue tracker ( https://issues.jboss.org/browse/RESTEASY-586 ) that I hope will get a reply eventually. I'm also using JBoss AS 7 and the latest RestEasy and CDI and Seam.

My application worked fine in Glassfish 3.1.1 but broke (with this "Duplicate context initialization parameter resteasy.injector.factory" error) when I moved it to JBoss AS 7.


The rest easy-cdi module has been bundled with J Boss AS since version 6.0.0 M4. so no need to add CdiInjectorFactory factory explicitly.

<context-param>
<param-name>resteasy.injector.factory</param-name>
<param-value>org.jboss.resteasy.cdi.CdiInjectorFactory</param-value>
</context-param>

But if you are using tomcat or any other server you need add this above line of code in web.xml.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜