• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rename to applicationContext-hibernate.xml.
 
Aranya Das
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did , still the same.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should work automatically.
You may try to remove:

And put applicationContext.xml in WEB-INF.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic