Results 1 to 5 of 5

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

  1. #1
    Join Date
    Nov 2004
    Location
    Geneva, Switzerland
    Posts
    3

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Athens, GA
    Posts
    20

    Default Re: How to reference a appcontext bean from xxx-servlet.xml

    Quote 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"/>

  3. #3
    Join Date
    Aug 2004
    Location
    Toulouse, France
    Posts
    148

    Default

    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

  4. #4
    Join Date
    Oct 2004
    Location
    Atlanta, GA
    Posts
    38

    Default 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

  5. #5
    Join Date
    Oct 2004
    Location
    Atlanta, GA
    Posts
    38

    Default Oops

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

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •