11 Replies Latest reply on Mar 14, 2007 3:50 PM by sshrestha

    late data source initialization

    sshrestha

      JBoss: 4.0.4, jvm: sun j2se 1.5.0_10
      I have a struts/hibernate webapp deployed in server/defcp/deploy/myApp.war and it uses a data source bound to jndi. Problem is the webapp/hibernate seems to start to initialize before the datasources are initialized: so the application initialization fails the first time.
      This probably happens because I have a Class that extends Struts' Plugin class which starts at application startup that make database calls.

      Then after the datasources are initialized properly, JBoss seems to initalize the webapp/hibernate again, and after that everything seems to work.

      Is there a way I can force all the datasources to initialize first before JBoss starts to work on the webapps?
      I looked at http://wiki.jboss.org/wiki/Wiki.jsp?page=DependOnDataSource. If I define a MBean for the datasource, would this problem go away?

        • 1. Re: late data source initialization
          weston.price

          Read this first:
          http://wiki.jboss.org/wiki/Wiki.jsp?page=DependOnDataSource


          Then take a look at the jboss-web.dtd and add the entry to a jboss-web.xml descriptor. Example:

          <jboss-web>
           <depends>jboss.jca:service=DataSourceBinding,name=(jndi-name)</depends>
          </jboss-web>
          


          • 2. Re: late data source initialization
            sshrestha

            I have added depends element in the jboss-web.xml, no change in results:
            here is my jboss-web.xml file:

            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">
            
            <jboss-web>
             <context-root>/</context-root>
             <virtual-host>xxx.mydomain.com</virtual-host>
            
             <resource-ref>
             <res-ref-name>jdbc/connAs400</res-ref-name>
             <jndi-name>java:/connAs400</jndi-name>
             </resource-ref>
            
             <resource-ref>
             <res-ref-name>jdbc/connMySql</res-ref-name>
             <jndi-name>java:/connMySql</jndi-name>
             </resource-ref>
            
            <depends>jboss.jca:service=DataSourceBinding,name=connAs400</depends>
            <depends>jboss.jca:service=DataSourceBinding,name=connMySql</depends>
            
            </jboss-web>
            


            • 3. Re: late data source initialization
              weston.price

              Hmmm...so check the basics

              1)The jboss-web.xml file is in WEB-INF, not META-INF
              2)The DataSource itself actually deploys and can be seen via the JMX console.


              Barring that, you may have to turn on tracing and post the result. Also, could you post your *-ds.xml file?

              • 4. Re: late data source initialization
                weston.price

                Also, eliminate the DTD reference in your jboss-web.xml file, or use the correct version (ie jboss-web_4.0.dtd etc).

                • 5. Re: late data source initialization
                  weston.price

                  Also, just to clarify, how are you deploying your DataSource? Deploying it inside the WAR archive will cause issues.

                  • 6. Re: late data source initialization
                    sshrestha

                    data source is deployed in deploy dir: mysql-ds.xml.
                    changed dtd version to 4_0.
                    still the same results.

                    by the way I don't have this problem if I deploy the application as a war file (myApp.war) directly in the deploy directory.
                    The reason I am deploying in myApp.war directory is to be able to front JBoss with Apache.

                    • 7. Re: late data source initialization
                      weston.price

                       


                      by the way I don't have this problem if I deploy the application as a war file (myApp.war) directly in the deploy directory.


                      What do you mean? Do you mean you are deploying this as an expanded directory structure? I might be missing something :-)

                      • 8. Re: late data source initialization
                        sshrestha

                        yes, this problem only occurs if I am deploying the application in a expanded directory (to be clearer: myApp.war is a directory: where I do jar -xf app.war).
                        and not if I deploy it as app.war (a war file) in deploy dir.

                        • 9. Re: late data source initialization
                          sshrestha

                          my mysql-ds.xml file:

                          <?xml version="1.0" encoding="UTF-8"?>
                          
                          <!-- $Id: mysql-ds.xml,v 1.3.2.3 2006/02/07 14:23:00 acoliver Exp $ -->
                          <!-- Datasource config for MySQL using 3.0.9 available from:
                          http://www.mysql.com/downloads/api-jdbc-stable.html
                          -->
                          <datasources>
                           <local-tx-datasource>
                           <jndi-name>wsMySql</jndi-name>
                          <connection-url>jdbc:mysql://10.0.0.105:3306/myData?autoReconnect=true</connection-url>
                           <driver-class>com.mysql.jdbc.Driver</driver-class>
                           <user-name>usr</user-name>
                           <password>pwd</password>
                           <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
                          
                           <min-pool-size>30</min-pool-size>
                           <max-pool-size>60</max-pool-size>
                          
                           <metadata>
                           <type-mapping>mySQL</type-mapping>
                           </metadata>
                           </local-tx-datasource>
                          
                          </datasources>
                          
                          


                          • 10. Re: late data source initialization
                            sshrestha

                            This is what my vhost entry looks like in server.xml file:

                             <Host name="xxx.mydomain.com" autoDeploy="false" deployOnStartup="false" deployXML="false" appBase="deploy" unpackWARs="true">
                             <Alias>yyy.mydomain.com</Alias>
                            
                             <Valve className="org.apache.catalina.valves.AccessLogValve"
                             prefix="xxx" suffix=".log" pattern="common"
                             directory="${jboss.server.home.dir}/log"/>
                            
                             <Context path="" docBase="${jboss.server.home.dir}/deploy/xxx.war" debug="0" reloadable="true"/>
                             </Host>
                            
                            


                            • 11. Re: late data source initialization
                              sshrestha

                              This is what my vhost entry looks like in server.xml file:

                               <Host name="xxx.mydomain.com" autoDeploy="false" deployOnStartup="false" deployXML="false" appBase="deploy" unpackWARs="true">
                               <Alias>yyy.mydomain.com</Alias>
                              
                               <Valve className="org.apache.catalina.valves.AccessLogValve"
                               prefix="xxx" suffix=".log" pattern="common"
                               directory="${jboss.server.home.dir}/log"/>
                              
                               <Context path="" docBase="${jboss.server.home.dir}/deploy/xxx.war" debug="0" reloadable="true"/>
                               </Host>