2 Replies Latest reply on Jul 13, 2012 1:59 AM by Jozef Hartinger

    It seems weld-2.0.0.Alpha2 doesn't work in tomcat 7?

    Newbie

      In web.xml, I put listener element.

       

        <listener>

          <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>

        </listener>

       

      The dependecy in pom.xml :

       

        <dependencies>

            <dependency>

                <groupId>org.jboss.weld.servlet</groupId>

                <artifactId>weld-servlet-core</artifactId>

                <version>2.0.0.Alpha2</version>

            </dependency>

            <dependency>

                <groupId>org.jboss.weld</groupId>

                <artifactId>weld-core</artifactId>

                <version>2.0.0.Alpha2</version>

                <exclusions>

                    <exclusion>

                        <artifactId>el-api</artifactId>

                        <groupId>javax.el</groupId>

                    </exclusion>

                </exclusions>

            </dependency>

        </dependencies>

       

      Everytime I start tomcat7, there's error in log:

       

      2012-7-4 13:59:36 org.apache.catalina.core.StandardContext listenerStart

      严重: Exception sending context initialized event to listener instance of class org.jboss.weld.environment.servlet.Listener

      java.lang.NullPointerException

          at org.jboss.weld.servlet.WeldListener.contextInitialized(WeldListener.java:114)

          at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.contextInitialized(ForwardingServletListener.java:37)

          at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:183)

          at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)

          at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)

          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

          at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)

          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

          at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)

          at org.apache.catalina.core.StandardService.start(StandardService.java:525)

          at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)

          at org.apache.catalina.startup.Catalina.start(Catalina.java:595)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

          at java.lang.reflect.Method.invoke(Method.java:597)

          at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)

          at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

       

      The code in WeldListener that cause Exception is :

       


      @Override

      public void contextInitialized(ServletContextEvent sce) {

      sce.getServletContext().setAttribute(BeanManager.class.getName(), beanManager);

      beanManager.fireEvent(sce, InitializedLiteral.APPLICATION);

      }

      Here, only one object could be null, that's "beanManager".

      In WeldListener line 87-88:

       


      @Inject

      private BeanManager beanManager;

      I think the problem is cause by these two lines. Maybe JBoss can inject BeanManager for WeldListener ( this is my guess), but tomcat cann't inject anything for WeldListener. In contrast, tomcat use WeldListener to initialize Weld Container.