tags:

views:

55

answers:

1

Hello! ok, i have another question now. I have a bunch of beans loaded succesfully in applicationContext.xml, which loads from web.xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>com.bamboo.common.factory.Log4JContextListener</listener-class>
</listener>

Here are is the bean defined in applicationContext.xml that i want to share:

<bean id="catalogFacadeTarget" class="com.bamboo.catW3.business.impl.CatalogFacadeImpl">
    <property name="categoryDAO"><ref local="categoryDAOTarget"/></property>
    <property name="containerDAO"><ref local="containerDAOTarget"/></property>
    <property name="productDAO"><ref local="productDAOTarget"/></property>
    <property name="productOptionDAO"><ref local="productOptionDAOTarget"/></property>
    <property name="productStatusDAO"><ref local="productStatusDAOTarget"/></property>
    <property name="userDAO"><ref local="userDAOTarget"/></property>
</bean>

it loads other beans (DAOs) which are initialized with hibernet.

I need to acces catalogFacadeTarget from the dispatcherServlet, declared in web.xml:

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

and configured dispatcher-servlet.xml like this:

<bean name="welcome"
    class="com.bamboo.catW3.business.impl.Welcome">
    <property name="successView">
        <value>welcome</value>
    </property>
     <property name="catalogFacadeImpl"><ref  local="catalogFacadeTarget"/></property>
</bean>

There! in the property called catalogFacadeImpl, i need the catalogFacadeTarget bean!

If you need the entire applicationContext.xml, web.xml, and dispatcher-servlet.xml please let me know.

From what i read, i should be able to share beans if i declared them in the contextConfigLocation configuration file.

Thank you very much in advance.

+2  A: 

The local attribute can only be used if the referencing bean is in the same context file.

A solution:

Replace

 <property name="catalogFacadeImpl"><ref local="catalogFacadeTarget"/></property>

with

 <property name="catalogFacadeImpl" ref="catalogFacadeTarget" />
Espen