Announcement Announcement Module
Collapse
No announcement yet.
Loading an Spring ApplicationContext in a J2EEContainer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loading an Spring ApplicationContext in a J2EEContainer

    Hi folks, now i have the following scenario:

    Basically i have an ear that contains a sar (Jboss service archive) with the hibernateServiceMbean. This ear basically calls a Mbean that creates the Hibernate SessionFactory and makes this SessionFactory available for all applications that i have (it loads all hibernate mappings build the session factory and makes this session factory available for all applications horizontally). After deploy this ear i can deploy my war´s and all web applications can access the session factory. It works fine but the problem is the sar is JBoss specific. If i want to deploy this MBean in Weblogic the approach is other. What is my idea, use the spring applicationContext to do this. I create en applicationContext.xml that looks like this:

    <?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="jmxAdapter"
    class="org.springframework.jmx.export.MBeanExporte r">
    <property name="beans">
    <map>
    <entry key="curso:service=HibernateService">
    <ref local="HibernateService" />
    </entry>
    </map>
    </property>
    </bean>

    <bean id="HibernateService" lazy-init="false" class="net.sf.hibernate.jmx.HibernateService" init-method="start">
    <property name="mapResources">
    <value>
    br/com/netservicos/core/bean/bb/BbEstqInstaladoraBean.hbm.xml,
    br/com/netservicos/core/bean/cp/CpAtividadeBean.hbm.xml,
    </value>
    </property>
    <property name="datasource" value="java:/BCV_SOC" />
    <property name="dialect"
    value="org.hibernate.dialect.Oracle9Dialect" />
    <property name="jndiName" value="java:/HibernateFactory_SOC" />
    </bean>

    <bean id="sessionFactory"
    class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="java:/HibernateFactory_SOC" />
    </bean>


    <!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->
    <bean id="transactionManager"
    class="org.springframework.transaction.jta.JtaTran sactionManager" />


    </beans>


    Using spring to start my Mbeans, i can start my MBeans in a single way in all j2ee containers. I understand that this mbean need to be deployed before my web application because it servers to all web applications that i developed. The problem is that i cant figure out a way to load this application context in the J2EE container without use the ContextLoaderListener web application based. is there some way to load an spring context in a j2ee container instead of use a web application ? If i use a web application to load the spring application context the web applcation classpath (WEB-INF/classes) must have the hibernate hbm.xml files and so on. I think that it´s not a good idea.

  • #2
    Check out http://forum.springframework.org/showthread.php?t=18383

    This shows how to create a parent context for your web app.
    Last edited by robyn; May 14th, 2006, 06:18 PM.

    Comment


    • #3
      This shows how to create a parent context for your web app

      Hi wpoitras, my question is how to load an Application Context without a web application. I dont want link my entity classes (hibernate) with a web application. I would like to load my hibernate classes with a standalone alone application context and bind my session factory in JNDI. In this way all my web applcations can access the session factory.

      Comment


      • #4
        I understand the problem you are trying to solve. A parent context would be a single context accessible from multiple web applications. Its loaded from a classpath. And your web application wouldn't really need to know that the hibernate objects weren't actually initialized inside the web applications. You would access them same way as the web objects (or could be referred to in your web application context). That would save you from having to look up the application context in the JNDI tree.

        If you wanted to add your application context to the JNDI tree you'd need to write some sort of custom start up class (depending on your application server).

        Comment


        • #5
          You could always create a SAR or something similar and export your objects as MBeans (JMX). Spring supports JMX exporting and importing and MBeans support starting and stoping where you can load context.

          Comment


          • #6
            There's nothing really that wrong with using a web-app as a mechanism to load something in a J2EE container. There doesn't have to be any web code in it of course. In that usage scenario, it's just a bootstrap mechanism, and a well-established one...

            Regards,

            Comment


            • #7
              Loading an Application Context in a J2EE Container !

              Hi folks, i have some corcerns about the subject.
              With this post in the forum i could realize some strategies to load the application context.

              Wpoitras saids that i can load a parent context that would be accessible from multiple web applications. I like this approach because this context is loaded from a classpath and your web application wouldn't really need to know that the hibernate objects weren't actually initialized inside the web applications. I could bind my application context to the JNDI tree too.

              Dvoitenko gives me the idea to load the context through MBean Start method, it is interesting but i cant realize how i cant inject my MBean without load my applcation context first.


              Colin saids that i can deploy a war (There doesn't have to be any web code in it of course) that calls the ContextLoaderListener and works only like a bootstrap mechanism. By the way my hbm files needs to be in the war´s class path.

              After all answers i need to know what is the best approach to load an application context that builds my hibernate session factory using spring.

              Best regards

              Comment

              Working...
              X