Announcement Announcement Module
Collapse
No announcement yet.
Deploying Spring web application in ear Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Deploying Spring web application in ear

    Hi

    I have been trying to deploy a web application deployed as an .ear file in Weblogic 8.1 SP 2. Whenever I deploy the application, it gives me an error saying unable to find the Hibernate configuration files in my .war file. If I explode the .ear file and deploy the application, it has no problems. My Hibernate .hbm.xml files are located in the same directory as the Java objects. The full filepath for the .hbm.xml and .class files in the .war file is "WEB-INF/classes/com/test/entities". I don't have a .jar file since I'm not using EJBs.

    Adrian

  • #2
    Can you post your configuration file fragment for the HibernateSessionFactory?

    You might need to add classpath: prefix to the configuration file location. This way spring will use classloader to load config files.

    Comment


    • #3
      Ok... Here's what I have for my DAO configuration:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

      <beans>
      <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
      <property name="jndiName">
      <value>myDataSource</value>
      </property>
      </bean>

      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
      <property name="dataSource">
      <ref bean="dataSource"/>
      </property>
      <property name="mappingDirectoryLocations">
      <list>
      <value>classpath:/com/test/entities</value>
      </list>
      </property>
      <property name="hibernateProperties">
      <props>
      <prop key="hibernate.dialect">org.hibernate.dialect.Orac le9Dialect</prop>
      </props>
      </property>
      </bean>

      <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.Hibernat eTemplate" singleton="false">
      <property name="sessionFactory">
      <ref bean="sessionFactory"/>
      </property>
      </bean>

      <bean id="myDAO" class="com.test.dao.MyDAOImpl" singleton="false">
      <property name="hibernateTemplate">
      <ref bean="hibernateTemplate"/>
      </property>
      </bean>
      </beans>

      Adrian
      Last edited by comebashme; Dec 13th, 2005, 02:35 AM.

      Comment


      • #4
        mappingDirectoryLocations will not work when you are zipped up in the war/ear. It didn't for me in Spring 1.2.2. That might have changed.
        I think it is an issue with the Java ClassLoader where classloader will only return single resource with ClassLoader.getResource() call.

        Give the following syntax a try. I did not try it before:
        classpath*:/com/test/entities/*.hbm.xml

        so it will look something like this:

        Replace
        Code:
        <property name="mappingDirectoryLocations">
        <list>
        <value>classpath:/com/test/entities</value>
        </list>
        </property>

        With
        Code:
        <property name="mappingResources">
        <list>
        <value>classpath*:/com/test/entities/*.hbm.xml</value>
        </list>
        </property>

        Comment


        • #5
          Ok... I have tried that and Weblogic is again making noise... Below is the noise it made:

          Context initialization failed
          org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory'

          defined in ServletContext resource [/WEB-INF/spring/dao-config.xml]: Initialization of bean failed; nested

          exception is java.io.FileNotFoundException: ServletContext resource

          [/classpath*:/com/test/entities/*.hbm.xml] cannot be resolved to absolute file path - web application

          archive not expanded?java.io.FileNotFoundException: ServletContext resource

          [/classpath*:/com/test/entities/*.hbm.xml] cannot be resolved to absolute file path - web application

          archive not expanded?

          Adrian

          Comment


          • #6
            Ok. so classpath*: will not work for the jared config files.

            The only other recourse you have is to include those files under WEB-INF somewhere and specify the path to them starting with /WEB-INF/

            As the error says Spring can only resolve classpath entries if they are not zipped up in the archive. If you include them under web-inf, Spring will be smart enough to use ServeltContext.loadResource to pull up those files.

            Dmitry

            Comment


            • #7
              Ok... I will try that. Will post the result here. Thanks for the help!

              Adrian

              Comment


              • #8
                OK... I have found where to place the .hbm.xml files... It seems that 'classpath:' refers to the .ear file's 'META-INF' folder. The dumb thing about this is that it can only reference to that location and nothing else, not even its sub-folders! I have only managed to get it to work by getting ANT to copy the .hbm.xml files to 'META-INF' folder, so now it has all the .hbm.xml files other than the standard application.xml and weblogic-application.xml files. Maybe the SPRING developers can look into this problem since it can be unsightly to lump the .hbm.xml files with weblogic-required .xml files.

                Comment


                • #9
                  It is not Spring limitation. It is Java classloader limitation.
                  Classloader was not designed to return you a list of files in the directory or some abstract regex path expression. It can only give you back a single resource or null if it is not found.
                  So cl.getResource("/com/x/x/config.xml");
                  you can get a URL to it or null... cl will not be able to process "com/x/x/*.xml". It just wasn't designed to handle that. In addition you have container specific class loading "niceties" that you must be aware of. It will be next to impossible to cover every posible situation.
                  But you deploy the application in exploded format, Spring can use java.io File and FileFilter to look for the files. That concept is much more flexible.

                  If you are curious take a look at the Resource abstraction in spring. I believe it covers a lot of situations.

                  Comment


                  • #10
                    Hmm... So troublesome to do something 'simple'. lol

                    Comment


                    • #11
                      Originally posted by comebashme View Post
                      OK... I have found where to place the .hbm.xml files... It seems that 'classpath:' refers to the .ear file's 'META-INF' folder. The dumb thing about this is that it can only reference to that location and nothing else, not even its sub-folders! I have only managed to get it to work by getting ANT to copy the .hbm.xml files to 'META-INF' folder, so now it has all the .hbm.xml files other than the standard application.xml and weblogic-application.xml files. Maybe the SPRING developers can look into this problem since it can be unsightly to lump the .hbm.xml files with weblogic-required .xml files.
                      You could also place the xml files at the root of the ear and use classpath:<whatever>.xml to access them.

                      Comment

                      Working...
                      X