Announcement Announcement Module
Collapse
No announcement yet.
Loading of multiple (hierarchical) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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 ?

      Comment


      • #4
        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;;

        Comment


        • #5
          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 ?

          Comment


          • #6
            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 ?

            Comment


            • #7
              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

              Comment


              • #8
                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.

                Comment

                Working...
                X