6 Replies Latest reply on Oct 2, 2013 11:50 AM by goldwater

    Get NPE using JNDI with Jboss AS7

    goldwater

      I checked on everything and seems well configured, this is a Spring application and no explicitly calling @Resource or Ctx anywhere within the application

       

      this is the error message from console

       

      00:55:37,867 INFO  [org.jboss.as.server] (HttpManagementService-threads - 3) JBA

      S015870: Deploy of deployment "MyApp.war" was rolled back with

      failure message {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"

      MyApp.war\".INSTALL" => "org.jboss.msc.service.StartException in se

      rvice jboss.deployment.unit.\"MyApp.war\".INSTALL: JBAS018733:

      Failed to process phase INSTALL of deployment \"MyApp.war\"

          Caused by: java.lang.NullPointerException"}}

       

      Error message from log

       

      00:55:37,852 WARN  [org.jboss.as.ee] (MSC service thread 1-4) JBAS011006: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to exception: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011054: Could not find default constructor for class org.springframework.web.context.request.async.StandardServletAsyncWebRequest

        at org.jboss.as.ee.component.ComponentDescription$DefaultComponentConfigurator.configure(ComponentDescription.java:606) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

        at org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:83) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:116)

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_35]

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_35]

        at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_35]

       

       

      00:55:37,862 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."MyApp.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."MyApp.war".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "MyApp.war"

        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:123) [jboss-as-server-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]

        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_35]

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_35]

        at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_35]

      Caused by: java.lang.NullPointerException

        at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.addJndiBinding(ModuleJndiBindingProcessor.java:261)

        at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:118)

        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:116) [jboss-as-server-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

        ... 5 more

       

      This is the JNDI data source setup in standalone.xml

       

                      <datasource jndi-name="java:/MyDS" pool-name="pool_oc" enabled="true" use-java-context="true">
                          <connection-url>jdbc:oracle:thin:@localhost:1521:orcl</connection-url>
                          <driver>oracle_driver</driver>
                          <pool>
                              <min-pool-size>1</min-pool-size>
                              <max-pool-size>2</max-pool-size>
                              <use-strict-min>false</use-strict-min>
                          </pool>
                          <security>
                              <user-name>username</user-name>
                              <password>password</password>
                          </security>
                          <validation>
                              <validate-on-match>false</validate-on-match>
                              <background-validation>false</background-validation>
                          </validation>
                          <statement>
                              <share-prepared-statements>false</share-prepared-statements>
                          </statement>
                      </datasource>
      
      
                          <driver name="oracle_driver" module="oracle">
                              <driver-class>oracle.jdbc.pool.OracleConnectionPoolDataSource</driver-class>
                          </driver>
      
      

       

      And this is the jndi configuration in web.xml

       

      <resource-ref>
        <description>JNDI Oracle Datasource</description>
        <res-ref-name>java:/MyDS</res-ref-name>
        <jndi-name>jdbc/MyDS</jndi-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        </resource-ref>
      
      

       

       

      Through all the application, the JNDI data source is named as jbdc/MyDS. But I guess that's not the issue.

       

      Then I really cannot think anything else might produce above error.

       

      Current Jboss core is: 7.1.2 Final, please help thanks.

        • 1. Re: Get NPE using JNDI with Jboss AS7
          jaikiran

          I think that NullPointerException has been fixed in a later version, from what I remember. But the real problem in your configuration is this:

           

          <res-ref-name>java:/MyDS</res-ref-name> 

          <jndi-name>jdbc/MyDS</jndi-name>


          The correct configuration (based on what you posted) should be:


          <res-ref-name>jdbc/MyDS</res-ref-name> 

          <jndi-name>java:/MyDS</jndi-name> 

           

           

          • 2. Re: Get NPE using JNDI with Jboss AS7
            goldwater

            HI Jaikiran

             

            Thanks for the response. But isn't the <res-ref-name/> for container JNDI config and <jndi-name/> is JNDI config within the application domain? So it is the other way around?

            • 3. Re: Re: Get NPE using JNDI with Jboss AS7
              sfcoy

              A <res-ref-nam>...</res-ref-name> element is a name in the JavaEE component namespace. You cannot put anything you want in there.

               

              Prior to JavaEE 6, the component namespace was very simple. If you had this:

              <res-ref-name>jdbc/myDataSource</res-ref-name>
              
              

              then in Java you would have to lookup in JNDI:

              DataSource myDataSource = (DataSource)context.lookup("java:comp/env/jdbc/myDataSource");
              
              

              ie. there is an implicit "java:comp/env" in front of the res-ref-name. Note that "comp" is an abbreviation of "component". Individual EJBs were each considered to be individual components, so they each had their own "java:comp/env" namespace in which too find resources. A web module was considered to be a whole module all together.

               

              JavaEE 7 introduced a some additional component namespaces:

              • java:module
              • java:app
              • java:global

              If you want to specify one of these namespaces, you must use the completely qualified name. The res-ref-name becomes:

              <res-ref-name>java:module/env/jdbc/myDataSource</res-ref-name>
              
              

              and the java code:

              DataSource myDataSource = (DataSource)context.lookup("java:module/env/jdbc/myDataSource");
              
              

              The JNDI name of the actual resource must appear in a <jndi-name>...</jndi-name> element as mentioned by jaikiran.

               

              See §EE.5.2.2 of "Java™ Platform, Enterprise Edition (Java EE) Specification, v6"

              • 4. Re: Get NPE using JNDI with Jboss AS7
                goldwater

                Hi Stephen

                 

                Please correct me if any misunderstanding, then in JBoss AS 7 the jndi name should be

                 

                <datasource jndi-name="java:comp/env/jdbc/MyDS" pool-name="pool_oc" enabled="true" use-java-context="true"> 

                 

                And in web.xml the res-ref-name should be

                 

                <res-ref-name>java:comp/env/jdbc/myDataSource</res-ref-name> 


                or


                <res-ref-name>jdbc/myDataSource</res-ref-name> 

                as AS7 officially support J2EE 6

                 

                and the JNDI name, which is specified for application-wise can be

                 

                <jndi-name>jdbc/AnyJNDINameIWant</jndi-name>

                 

                Is it correct?

                Thanks again.

                • 5. Re: Re: Get NPE using JNDI with Jboss AS7
                  sfcoy

                  Almost, but not quite.

                   

                  Your datasource declaration should be:

                  <datasource jndi-name="java:jboss/datasources/AnyJNDINameIWant" pool-name="pool_oc" enabled="true" use-java-context="true"> 
                  

                   

                  and the jndi-name element in the resource reference should be the same as the jndi-name in the datasource declaration above:

                  <jndi-name>java:jboss/datasources/AnyJNDINameIWant</jndi-name>
                  

                   

                  The resource-ref links the name that you lookup in code ("java:comp/env/jdbc/myDataSource") to the actual resource in the server configuration ("java:jboss/datasources/AnyJNDINameIWant").

                   

                  The java:comp|module|app|global JNDI namespaces all have a scope within your application, outside of which they have no meaning. Therefore using "java:comp/env/..." in your datasource declaration makes no sense.

                  1 of 1 people found this helpful
                  • 6. Re: Get NPE using JNDI with Jboss AS7
                    goldwater

                    Hi Stephen

                     

                    Thanks for pointing out the JNDI definition diversity for J2EE7, it finally works after I made the jndi reference to :

                     

                    1. <resource-ref> 
                    2.   <description>JNDI Oracle Datasource</description> 
                    3.   <res-ref-name>java:module/env/MyDS</res-ref-name> 
                    4.   <jndi-name>jdbc/MyDS</jndi-name> 
                    5.   <res-type>javax.sql.DataSource</res-type> 
                    6.   <res-auth>Container</res-auth> 
                    7.   </resource-ref> 

                     

                    Not sure why need to specifically declare the java:module/env/ prefix. I guess because the datasource should be treated as a module per application-wise? Without such prefix then application complains about "missing dependency" and stop deploying(meaning must place that prefix explicitly.)

                     

                    Thanks again.