4 Replies Latest reply on Apr 2, 2012 9:15 AM by manarh

    Seam 2.2.2.Final on JBoss AS 7: @In gives NPE

    pdhaigh

      Hi,

       

      I have been working on migrating an application based on Seam 2.2.2.Final to JBoss AS 7. I've worked through Marek's examples, and various other documentation, and have got to the point where the application deploys with no errors (although I did have to downgrade to AS 7.1.0 from 7.1.1 due to this bug: Caused by: java.lang.NoClassDefFoundError: org/hibernate/cache/infinispan/InfinispanRegionFactory)

       

      The steps I have taken are:

       

      components.xml

       

      <core:init jndi-pattern="java:app/myapp/#{ejbName}" debug="false" distributable="false"/>
      <component class="org.jboss.seam.transaction.EjbSynchronizations" jndi-name="java:app/myapp/EjbSynchronizations"/>

      <component class="org.jboss.seam.async.TimerServiceDispatcher" jndi-name="java:app/myapp/TimerServiceDispatcher"/>

       

      jboss-deployment-structure.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

        <deployment>

          <!-- This allows you to define additional dependencies, it is the same as using the Dependencies: manifest attribute -->

          <dependencies>

            <module name="org.apache.commons.logging" />

            <module name="javax.faces.api" slot="1.2"/>

            <module name="com.sun.jsf-impl" slot="1.2"/>

            <module name="org.dom4j" export="true"/>

          </dependencies>

          <exclusions>

              <module name="javax.faces.api" slot="main"/>

              <module name="com.sun.jsf-impl" slot="main"/>

            </exclusions>

        </deployment>

      </jboss-deployment-structure>

       

      web.xml


      <context-param>
        <param-name>org.jboss.jbossfaces.JSF_CONFIG_NAME</param-name>
        <param-value>Mojarra-1.2</param-value>
      </context-param>

       

      Included jsf-facelets.jar in WAR, and bundled hibernate:

       

      pom.xml

       

      <dependency>

          <groupId>org.jboss.seam</groupId>

          <artifactId>jboss-seam</artifactId>

          <version>2.2.2.Final</version>

      </dependency>

       

      <dependency>

          <groupId>org.richfaces.ui</groupId>

          <artifactId>richfaces-ui</artifactId>

          <version>3.3.3.Final</version>

      </dependency>

      <dependency>

          <groupId>org.richfaces.framework</groupId>

          <artifactId>richfaces-impl</artifactId>

          <version>3.3.3.Final</version>

      </dependency>

       

      <dependency>

          <groupId>com.sun.facelets</groupId>

          <artifactId>jsf-facelets</artifactId>

          <version>1.1.14</version>

          <scope>provided</scope>

      </dependency>

       

      <dependency>

          <groupId>org.hibernate</groupId>

          <artifactId>hibernate-core</artifactId>

          <version>3.6.9.Final</version>

      </dependency>

      <dependency>

          <groupId>org.hibernate</groupId>

          <artifactId>hibernate-entitymanager</artifactId>

          <version>3.6.9.Final</version>

      </dependency>

      <dependency>

          <groupId>org.hibernate</groupId>

          <artifactId>hibernate-validator</artifactId>

          <version>3.1.0.GA</version>

      </dependency>

       

       

      The application deploys fine, and I can access pages, with facelets templating and EL expressions resolving. However, wherever I have @In, I am getting a NPE:

       

      @Stateless

      @Name("authenticator")

      public class AuthenticatorAction implements Authenticator

      {

      @In

      Identity identity;

       

      public boolean authenticate()

      {

          log.info("Authenticating #0", identity.getCredentials().getUsername());

       

       

      gives NPE on log line and:

       

      @Stateful

      @Name("leagueManager")

      public class LeagueManager implements LeagueManagerI

      {

       

      @In (create=true,required=false)

      private LeagueDAO leagueDAO;

       

      public void checkLeague()

      {

          if (leagueDAO.getInstance().getId()==null)

       

      gives NPE on the last line. However, using Component.getInstance(), does work:

       

      @Stateful

      @Name("leagueManager")

      public class LeagueManager implements LeagueManagerI

      {

       

      @In (create=true,required=false)

      private LeagueDAO leagueDAO;

       

      public void checkLeague()

      {

          leagueDAO = (LeagueDAO) Component.getInstance("leagueDAO");

          if (leagueDAO.getInstance().getId()==null)

       

      So it appears that Seam is functioning, but the Injection is failing for some reason. Can anyone help shed some light?

       

      cheers

       

      phil

        • 1. Re: Seam 2.2.2.Final on JBoss AS 7: @In gives NPE
          manarh

          Phil,

           

          do you use Hibernate 3.6 intentionally?

           

          Also you don't have excluded hibernate 4, which are default in AS7.

          • 2. Re: Seam 2.2.2.Final on JBoss AS 7: @In gives NPE
            pdhaigh

            In case this proves helpful to anyone else...

             

            I have realised the issue was that the EJB annotations were not being honoured; I have moved to a WAR packaging (taking advantage of now being able to package EJBs in a WAR in J2EE6) - but this means that the required location for the ejb-jar.xml file (which configures the SeamInterceptor) has changed to WEB-INF. Adding the file to there means all is now working.

             

            cheers

             

            phil

            • 3. Re: Seam 2.2.2.Final on JBoss AS 7: @In gives NPE
              pdhaigh

              Hi Marek,

               

              Sorry, you replied about 2 seconds before I posted my solution!

               

              In answer to your questions:

               

              1. Yes, 3.6.9 is intentional - I had issues with versions prior to 3.5, so decided to go for 3.6.9. It seems to be working..

              2. I should probably have also posted my persistence.xml file, which contains the properties below, which force the application to use it's own version of hibernate.

               

              <property name="jboss.as.jpa.managed" value="false"/>

              <property name="jboss.as.jpa.providerModule" value="hibernate3-bundled" />

               

              cheers

               

              phil

              • 4. Re: Seam 2.2.2.Final on JBoss AS 7: @In gives NPE
                manarh

                Cool, basically it should work, but there are some edge corner use cases, when it doesn't work even Seam2 uses proxy objects for JPA.