Note that there are some explanatory texts on larger screens.

plurals
  1. POWeld Servlet not working when downgrading from JBoss AS 7 to JBoss AS 5
    primarykey
    data
    text
    <p>I have an app that runs fine on jboss7, it uses jee6 apis: jax-rs and CDI. Due to production limitations I was asked to adapt it to run on Jboss 5.1.0. To make things easy I created a minimal application, with only one service and one injection. It works fine on jb7, and I had to add the libs that are not provided for the jboss5 version. </p> <p>jax-rs worked fine, I added RestEasy and declared the RestEasy servlet on the web.xml.</p> <p>For CDI I included Weld, to work on servlet mode, since the application does not have servlets. Following the docs, I included the listener on the web.xml, and then found on a jboss forum that another listener is necessary to register the BeanContext to the jboss jndi. </p> <p>So what I have is:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt; &lt;listener&gt; &lt;listener-class&gt;org.jboss.weld.environment.servlet.Listener&lt;/listener-class&gt; &lt;/listener&gt; &lt;listener&gt; &lt;listener-class&gt;org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;servlet&gt; &lt;servlet-name&gt;resteasy-servlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;javax.ws.rs.Application&lt;/param-name&gt; &lt;param-value&gt;br.com.bvmf.services.ApplicationConfig&lt;/param-value&gt; &lt;/init-param&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;resteasy-servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;session-config&gt; &lt;session-timeout&gt; 30 &lt;/session-timeout&gt; &lt;/session-config&gt; &lt;/web-app&gt; </code></pre> <p>For the build I am using Gadle, but just to have a better understanding for not I am inserting most of the jars manually for now:</p> <pre><code>apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'war' webAppDirName = 'WebContent' repositories { mavenCentral() flatDir name:'EasyRestJars',dirs:'libs' } dependencies { compile( [name : 'weld-servlet', version : '2.0.0.SP1-jboss5'], [name : 'jaxrs-api', version : '2.3.6.Final'], [name : 'jackson-core-asl', version : '1.9.9'], [name : 'jackson-jaxrs', version : '1.9.9'], [name : 'jackson-mapper-asl', version : '1.9.9'], [name : 'resteasy-jackson-provider', version : '2.3.6.Final'], [name : 'resteasy-jaxb-provider', version : '2.3.6.Final'], [name : 'resteasy-jaxrs', version : '2.3.6.Final'], [name : 'scannotation', version : '1.0.3'] ) providedCompile( [group: 'org.slf4j', name: 'slf4j-api', version: '1.5.6'], [group: 'javaee', name: 'javaee-api', version: '5' ] ) testCompile group: 'junit', name: 'junit', version: '4.+' } test { systemProperties 'property': 'value' } war{ exclude 'WEB-INF/lib/*' } </code></pre> <p>Now the three classes:</p> <p>Tha application config just returns the service:</p> <pre><code>@ApplicationPath("min") public class ApplicationConfig extends Application { @Override public Set&lt;Class&lt;?&gt;&gt; getClasses() { Set&lt;Class&lt;?&gt;&gt; resources = new java.util.HashSet&lt;Class&lt;?&gt;&gt;(); resources.add(br.com.bvmf.services.HelloWorldResource.class); return resources; } } </code></pre> <p>The bean that should be injected:</p> <pre><code>public class HelloProvider { public String getString() { return "Injected Hello"; } } </code></pre> <p>And the service itself:</p> <pre><code>@Path("/helloworld") public class HelloWorldResource { @Inject private HelloProvider provider; @GET public String getMessage() { //This is where I get a null pointer return provider.getString(); } } </code></pre> <p>So the bean is not injected, just that. During the deploy, the log reads:</p> <pre><code>2013-06-04 15:24:31,371 INFO [org.jboss.webbeans.bootstrap.WebBeansBootstrap] (HDScanner) Web Beans 1.0.0.PREVIEW1 2013-06-04 15:24:32,898 INFO [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (HDScanner) deploy, ctxPath=/min-cil-1.0-SNAPSHOT 2013-06-04 15:24:33,417 INFO [org.jboss.weld.Version] (HDScanner) WELD-000900 2.0.0 (SP1) 2013-06-04 15:24:33,774 INFO [org.jboss.weld.Bootstrap] (HDScanner) WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously. 2013-06-04 15:24:34,485 WARN [org.jboss.weld.Bootstrap] (HDScanner) Legacy deployment metadata provided by the integrator. Certain functionality will not be available. 2013-06-04 15:24:34,809 INFO [org.jboss.weld.environment.tomcat.Tomcat6Container] (HDScanner) Tomcat 6 detected, CDI injection will be available in Servlets and Filters. Injection into Listeners is not supported 2013-06-04 15:24:35,750 INFO [org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener] (HDScanner) BeanManager reference bound to java:comp/env/BeanManager 2013-06-04 15:26:13,648 INFO [org.jboss.resteasy.spi.ResteasyDeployment] (http-127.0.0.1-8080-2) Deploying javax.ws.rs.core.Application: class br.com.bvmf.services.ApplicationConfig </code></pre> <p>There is a note in the <a href="http://docs.jboss.org/weld/reference/latest/en-US/html/environments.html" rel="nofollow">weld docs</a> saying that: "Additionally, Weld Servlet supports JBoss EAP 5.1, to do this use the jboss5 variant of Weld Servlet." So I found this version, but it made no difference (besides more problems with slf4j).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload