aspose file tools*
The moose likes Spring and the fly likes How to access application-context beans in dispatcher-servlet.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to access application-context beans in dispatcher-servlet.xml" Watch "How to access application-context beans in dispatcher-servlet.xml" New topic
Author

How to access application-context beans in dispatcher-servlet.xml

Aranya Das
Greenhorn

Joined: Aug 19, 2009
Posts: 2
Hi,

I have defined dao beans in application-context.xml and want to access it in dispatcher-servlet.xml.
Can anyone please guide me how to do that ?

Below are my config files.

web.xml :

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-hibernate.xml</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<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>*.do</url-pattern>
</servlet-mapping>

application-context.xml :

<bean id="IssueMasterDAOTarget" class="com.ess.dao.IssueMasterDAOImpl">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<bean id="IssueMasterDAO" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref local="transactionManager"/></property>
<property name="target"><ref local="IssueMasterDAOTarget"/></property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="store*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

dispatcher-servlet.xml :

<bean id="issueService" class="com.ess.service.IssueServiceImpl">
<property name="issueMasterDAO"><ref bean="issueMasterDAO"/></property>
</bean>

I get the below error while startup of application

2009-08-19 12:11:16,376 ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/IssueTracker] - StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'issueService' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'issueMasterDAO' while setting bean property 'issueMasterDAO'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'issueMasterDAO' is defined

Please help and thanks in advance.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Rename to applicationContext-hibernate.xml.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Aranya Das
Greenhorn

Joined: Aug 19, 2009
Posts: 2
I did , still the same.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
It should work automatically.
You may try to remove:

And put applicationContext.xml in WEB-INF.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access application-context beans in dispatcher-servlet.xml