Announcement Announcement Module
Collapse
No announcement yet.
Reference other context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reference other context

    Hi, I've seen some of you post a question much like this one, and I've seen the answers but I still can't figure it out.
    I have an ejb-jar archive that loads an application context. I have some session bean that interact with daos, all managed by spring. I also have some business delegates that talk to session beans (facades).
    That context is an applicationContext.xml located in WEB-INF jar folder.

    And I have a struts web application, that will perform its task by calling the business delegates.

    The problem is that when I reference the business delegates from the web tier application context, spring says it can't resolve the reference.

    This is my configuration:

    action-servlet.xml
    Code:
    <beans>
    	<bean name="/totem/doSomething"
    		class="com.genesis.DoSomethingAction" singleton="false">
    		<property name="doSmthBD">
    			<ref bean="doSmthBDelegate" />
    		</property>
    	</bean>
    </beans>
    These are some things in struts-config.xml:
    Code:
     <action attribute="doSmthForm"
    			name="doSmthForm"
    			path="/totem/doSomething" validate="false"
    			scope="session"
    			type="org.springframework.web.struts.DelegatingActionProxy"/>
    			
    	<plug-in
    		className="org.springframework.web.struts.ContextLoaderPlugIn">
    		<set-property property="contextConfigLocation"
    			value="/WEB-INF/action-servlet.xml" />
    	</plug-in>
    In web.xml I load the listener without further reference to anything else:
    Code:
    		<listener>
    			<listener-class>
    				org.springframework.web.context.ContextLoaderListener
    			</listener-class>
    		</listener>
    How do I reference applicationContext.xml from action-servlet.xml so spring glue them all?

  • #2
    In web.xml I load the listener without further reference to anything else:
    Code:
          <listener> 
             <listener-class> 
                org.springframework.web.context.ContextLoaderListener 
             </listener-class> 
          </listener>
    ContextLoaderListener looks by default at /WEB-INF/applicationContext.xml and create the root WebApplicationContext. ContextLoaderPlugIn uses this context, automatically, as the parent of the context it create for action-servlet.xml. This means that beans configured in applicationContext.xml can be referenced by beans in action-servlet.xml.
    How do I reference applicationContext.xml from action-servlet.xml so spring glue them all?
    Can you elaborate more on what happens when you start your server? log, exceptions...

    Comment


    • #3
      Thanks for your answer!

      My server starts ok. I get an exception when I invoke a method on a business delegate that is managed from other context.

      The problem is that, as you said, ContextLoaderListener loads the root WebApplicationContext, and then the pluggin loads the actions context.

      But the problem is that I have a session bean (that extends AbstractStatelessSessionBean) that loads its own context (by seeing the ejb env entry ejb/BeanFactoryPath).

      These two contexts should be related (I think the context loaded by my session beans should be parent of web context, right?), but I don't know how.

      Thanks!

      Comment


      • #4
        ndobler,

        I think it would be a good idea to separate the two contexts (EJB and Web). You can for instance keep the context loaded by the EJB as is, and configure the business delegates inside the web context.

        Comment


        • #5
          I think the easiest way to handle this problem is described by Matt Raible at the following link:

          http://www.jroller.com/page/raible?a...g_config_files

          Comment

          Working...
          X