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

落爺英雄遲暮 提交于 2019-12-02 00:41:21

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

Harshith Hanthur

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!