Results 1 to 7 of 7

Thread: Loading an Spring ApplicationContext in a J2EEContainer

  1. #1

    Default 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. #2
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    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 at 06:18 PM.

  3. #3

    Default 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.

  4. #4
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    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).

  5. #5
    Join Date
    May 2005
    Location
    San Francisco
    Posts
    61

    Default

    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.

  6. #6
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    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,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  7. #7

    Default 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

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 2
    Last Post: Dec 8th, 2005, 09:00 AM
  3. how to use hibernate lazy loading with spring transaction
    By tanmoy.chakraborty in forum Data
    Replies: 1
    Last Post: Oct 11th, 2005, 02:07 AM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Replies: 7
    Last Post: Oct 6th, 2004, 02:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •