Announcement Announcement Module
Collapse
No announcement yet.
How to reference a appcontext bean from xxx-servlet.xml ???? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to reference a appcontext bean from xxx-servlet.xml ????

    Hi,

    In my staterkit-servlet.xml I have besides Dispatcher....
    a bean wich reference a facade which is declared in my applicationcontext.

    in my starterkit-servlet.xml :
    <bean name="mainview.htm" class="myPackage.MainViewController">
    <property name="facade">
    <ref parent="starterkitFacade"/></property>
    </bean>

    in my application context.xml I have
    <bean id="starterkitFacade" class="myPackage.StarterKitImpl">
    (some properties binding DAO goes here)
    </bean>

    in my web.xml
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    and

    <servlet>
    <servlet-name>starterkit</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    So I load DAO information in my application context and I can't access beans declared there from the servlet point of view

    On starting I have this error
    Error creating bean with name 'mainview.htm' defined in resource [/WEB-INF/starterkit-servlet.xml] of ServletContext: Can't resolve reference to bean 'starterkitFacade' while setting property 'facade'

    It can't ref the starterKitFacade coming from applicationContext !!!

    What I am doing wrong ???

    Thanks for your help

  • #2
    Re: How to reference a appcontext bean from xxx-servlet.xml

    Originally posted by Kesasar
    Hi,

    in my starterkit-servlet.xml :
    <bean name="mainview.htm" class="myPackage.MainViewController">
    <property name="facade">
    <ref parent="starterkitFacade"/></property>
    </bean>
    <ref parent="starterkitFacade"/> --> <ref bean="starterkitFacade"/>
    or
    <ref parent="starterkitFacade"/> --> <ref local="starterkitFacade"/>

    Comment


    • #3
      Actually, only the <ref bean="starterkitFacade" /> should work. The version attribute 'local' is only used to point at beans declared in the very same xml file (it enforce this using IDREF xml type).

      Olivier

      Comment


      • #4
        Same problem

        I am having the same problem. In my *-servlet.xml file, I try to reference a bean declared in the applicationContext.xml file and get an error stating the reference can not be resolved. Is there any special way you have to reference a bean that is outside of the *-servlet context? The documentation seems to indicate that the default context will be used as a parent for the web application context. Here is a quote from the Javadoc:
        By default, the configuration will be taken from "/WEB-INF/applicationContext.xml" for the root context, and "/WEB-INF/test-servlet.xml" for a context with the namespace "test-servlet" (like for a DispatcherServlet instance with the web.xml servlet-name "test"). These config location defaults can be overridden via setConfigLocations, respectively via the "contextConfigLocation" parameters of ContextLoader and FrameworkServlet.
        In my particular case, I am setting the "contextConfigLocation" for the DispatcherServlet to include an extra file, but am not overriding the default behavior for the default context. My assumtion is that I will end up with a web application context that merges the files configured in the dispatcher init param and with a parent context that is the default context. Anybody out there have this working? I am using Spring 1.1.1.

        Thanks!
        Derek Adams

        Comment


        • #5
          Oops

          Never mind.. I forgot to add the ContextLoaderListener to my web.xml. :oops:

          Comment

          Working...
          X