In the JSF 2.0 application (running on Tomcat 7 and using welding 1.1.1.Final), I want to offer my user to download some binary files (.doc, .pdf, etc.).
To satisfy this need, I want to use the JAX-RS (RESTEasy 2.2.0.Final) bean resource (annotated with @Path). The problem is that inside the bean I want to call a service from a field annotated with an annotation @Inject.
Actually, as a welder user trying a similar thing I have NullPointerException: Weld does not introduce me my service.
So, I read a post in the JBoss community about how to integrate RESTEasy with CDI , so I made my maven war project dependent on org.jboss.resteasy:resteasy-cdiand here is mine web.xml:
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<filter>
<filter-name>ConversationPropagationFilter</filter-name>
<filter-class>org.jboss.weld.servlet.ConversationPropagationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ConversationPropagationFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
<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>/rest/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
The problem is that when my application loads, I have this exception:
java.lang.RuntimeException: Unable to instantiate InjectorFactory implementation.
at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:141)
at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28)
...
Caused by: java.lang.NullPointerException
at org.jboss.resteasy.cdi.CdiInjectorFactory.lookupBeanManager(CdiInjectorFactory.java:116)
at org.jboss.resteasy.cdi.CdiInjectorFactory.<init>(CdiInjectorFactory.java:41)
...
at java.lang.Class.newInstance(Class.java:308)
at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:133)
And when I delete the context parameter resteasy.injector.factory, I have NPEwhen trying to get my service from a field variable annotated with @Inject...
Does anyone know how to configure RESTEasy beans to control Weld (and make injection into JAX-RS resources possible)?
source
share