Announcement Announcement Module
Collapse
No announcement yet.
Newbie question - Application contexts Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie question - Application contexts

    Hello,
    I have a problem referencing beans between different files. My web.xml file is:

    Code:
     <context-param>
      	<param-name>contextConfigLocation</param-name>
      	<param-value>/WEB-INF/applicationContext.xml</param-value>
      </context-param>
      <!-- Spring Context Loader -->
    
      <servlet>
        <servlet-name>context</servlet-name>
        <servlet-class>org.springframework.web.ContextLoaderServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
    
      <!-- Spring Dispatcher -->
    
      <servlet>
        <servlet-name>CultureApp</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
      </servlet>
    my applicationContext.xml file is:

    Code:
    <beans>
    
    	<!-- ========================= BUSINESS DEFINITIONS ========================= -->
    	<bean id="bizData" class="ca.culture.business.CultureBusinessData"/>
    
    
    </beans>
    and my CultureApp-servlet.xml file is

    Code:
    <beans>
    
        <!--  Controller for the initial Culture.ca page -->
        <bean id="CultureAppController" class="ca.culture.spring.CultureAppController">
        	<property name="businessData"><ref bean="bizData"/></property>
        </bean>
    
    
    </beans>
    My problem is that every time I start this with Tomcat 4, I get the error indicating that it cannot resolve [No bean named 'bizData' is defined]. How can beans defined in the application context be referenced in other context (.xml files) ???

    Thanks

  • #2
    Your configration seems correct, except for org.springframework.web.ContextLoaderServlet that should be org.springframework.web.context.ContextLoaderServl et.

    ContextLoaderServlet/ContextLoaderListener load applicationContext.xml and register it as the root WebApplicationContext. Then each DispatcherServlet loads its corresponding <servletname>-servlet.xml and binds it to the root WebApplicationContext. This way, your can reference root wac beans in your servlet context.

    jpetstore sample, from Spring distribution, shows this configuration in action.

    Could you provide the error log you receive in tomcat?

    Comment


    • #3
      Originally posted by irbouho
      Your configration seems correct, except for org.springframework.web.ContextLoaderServlet that should be org.springframework.web.context.ContextLoaderServl et.
      ...
      Dumb error from my part. This did it. Thanks.

      Comment

      Working...
      X