Illegal to inject a message body into a singleton into public org.codehaus.jackson.jaxrs.JacksonJsonProvider

Problem

Using Jackson as JSON provider in RESTEasy.


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

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

With RESTEasy auto scanning enabled.


	<context-param>
		<param-name>resteasy.scan</param-name>
		<param-value>true</param-value>
	</context-param>

When starting up, it hits following errors and failed to start up any of the RESTEasy services.


SEVERE: Exception sending context initialized event to listener instance of class 
	org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
java.lang.RuntimeException: Unable to instantiate MessageBodyReader
	at org.jboss.resteasy.spi.ResteasyDeployment.registerProvider(ResteasyDeployment.java:505)
	at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:305)
	at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:225)
	//...
Caused by: java.lang.RuntimeException: 
        Illegal to inject a message body into a singleton into public
	org.codehaus.jackson.jaxrs.JacksonJsonProvider(
	org.codehaus.jackson.map.ObjectMapper,org.codehaus.jackson.jaxrs.Annotations[])
	... 20 more

Solution

There is problem to integrate RESTEasy with Jackson if “auto scanning” mode is enabled. Hope it will fixed in later released.

To fix it, disabled the auto scanning feature, and register your RESTEasy service manually in web.xml.


	<!-- disabled auto scanning
	<context-param>
		<param-name>resteasy.scan</param-name>
		<param-value>true</param-value>
	</context-param>
        -->
	<context-param>
		<param-name>resteasy.resources</param-name>
		<param-value>com.mkyong.JacksonRestServiceHere</param-value>
	</context-param>

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
3 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
JAX-RS TUTORIALS | BUYWORKSELLRahul KIntegrate Jackson with RESTEasy Recent comment authors
newest oldest most voted
trackback
Integrate Jackson with RESTEasy

[…] the RESTEasy auto scanning, and register your REST service manually, otherwise, you will hits this error. Hope it get fix in future release.File : web.xml <!– disabled auto scan <context-param> […]

trackback
JAX-RS TUTORIALS | BUYWORKSELL

[…] Illegal to inject a message body into a singleton into public org.codehaus.jackson.jaxrs.JacksonJson… […]

Rahul K
Guest
Rahul K

I tried this however I found it better to upgrade to the version 2.2.3 of resteasy-jaxrs and resteasy-jackson-provider. this issue is fixed there.