Results 1 to 8 of 8

Thread: Loading of multiple (hierarchical)

  1. #1

    Default Loading of multiple (hierarchical)

    Loading of multiple (hierarchical) contexts, allowing each to be focused on one particular layer, for example the web layer of an application
    This quote comes from the reference manual, but i've failed to find some description on how to do so.. (it should have been 3.12.4 but there no ToDo marks there, so I wonder if the doc is not somewhere else...)

    Is this done thought postBeanFactory and stuff like that ?
    Is there methods in the AppContext package ( i haven't find any , but this doesn't there not there)...

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Take a look at the samples. For example, JPetstore has this in it's web.xml:
    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			/WEB-INF/dataAccessContext-local.xml  /WEB-INF/applicationContext.xml
    		</param-value>
    		<!--
    		<param-value>
    			/WEB-INF/dataAccessContext-jta.xml  /WEB-INF/applicationContext.xml
    		</param-value>
    		-->
    	</context-param>
    The other context, petstore-servlet.xml, is loaded by the DispatcherServlet called petstore.
    Code:
    	<servlet>
    		<servlet-name>petstore</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<load-on-startup>2</load-on-startup>
    	</servlet>
    This demonstrates at least 3 layers of config (not including remoting) which can easily be re-configured.

  3. #3

    Default

    Given i'm quite new to both tomcat and spring, it may be a silly question : but how my code choose the proper context ? Do I have to do it programmaticly or just map some page to some context ?

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    but how my code choose the proper context ?
    If the above doesn't make sense, I can only suggest reviewing the samples, and maybe try a simple application that loads multiple contexts using something like:
    applicationContext1.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	<bean id="bean1" class="java.lang.String">
    		<constructor-arg index="0"><value>bean1</value></constructor-arg>
     	</bean>
    </beans>
    applicationContext2.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	<bean id="bean2" class="java.lang.String">
    		<constructor-arg index="0"><value>bean2</value></constructor-arg>
     	</bean>
    </beans>
    Code:
    String&#91;&#93; paths = new String&#91;&#93; &#123;"applicationContext1.xml", "applicationContext2.xml"&#125;;
    ApplicationContext ctx = new ClassPathXmlApplicationContext&#40;paths&#41;;
    ctx.getBean&#40;"bean1"&#41;;

  5. #5

    Default

    Okay i get it...
    You can get the context if your class if application context aware, and then use it programmaticly.
    Moreover, those context are defined in a Spring's XML files ( i believe it used the <context> of Tomcat's, so i didn't understand why it seems to be a Spring's features).

    So, if i got it right : Let's say i realize a web app that use hibernate, and a db, for the sole purpose of displaying a list of object extracted from a db ( list of products). I'll define the web context i Tomcat, and then I'll be able through Spring to define a context for each layer ( one for the user and another for the hibernate session) ? ... Or did I miss understood something ?

  6. #6

    Default

    There is a last thing I wonder about those context loading : in what sens are they Hierarchical ?

    The way I see it, it means, that you can access the context of a diffrent layer easily ( let's say, access the aplication layer to get some user's data in the hibernate session). Or , again have I let my self be mislead ?

  7. #7
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Let's say i realize a web app that use hibernate, and a db, for the sole purpose of displaying a list of object extracted from a db ( list of products). I'll define the web context i Tomcat, and then I'll be able through Spring to define a context for each layer
    That's right. Because it is layered, you could, for example, write data integration tests that just use the data related contexts (without loading the web-contexts at all). To try this, take a look at: org.springframework.test

  8. #8
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    in what sens are they Hierarchical...The way I see it, it means, that you can access the context of a diffrent layer easily
    I think that's it. The contexts allow you to layer your application. I think it's up to the designer to implement this layering though.

Similar Threads

  1. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  2. Replies: 3
    Last Post: May 16th, 2005, 07:04 AM
  3. Replies: 1
    Last Post: Mar 9th, 2005, 03:52 PM
  4. Replies: 1
    Last Post: Feb 25th, 2005, 07:12 AM
  5. Multiple Pages
    By afida in forum Swing
    Replies: 12
    Last Post: Feb 16th, 2005, 08:42 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
  •