Results 1 to 3 of 3

Thread: applicationContext.xml and <application>-servlet.xml

  1. #1

    Default applicationContext.xml and <application>-servlet.xml

    Hi,

    I am using spring dao template classes for interacting with database. I have defined my datasource in applicationContext.xml and mentioned the same in web.xml as
    Code:
      <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/applicationContext.xml</param-value>
    	</context-param>
    and I got the following error message
    Code:
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jdbcTemplate' is defined
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:387)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:968)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    I am able to connect to database, if I put the datasource configuration in my <application>-servlet.xml file. So, this states that my applicationContext.xml is not getting picked up. Did I miss anything?

    Thanks,
    Gupta

  2. #2
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    Do you also have this in your web.xml?

    Code:
        <listener>
            <listener-class>
                org.springframework.web.context.ContextLoaderListener
            </listener-class>
        </listener>
    Here's what my web.xml looks like:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <web-app
        id="WebApp_ID" version="2.5"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="
            http://java.sun.com/xml/ns/javaee
            http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <display-name>whatever</display-name>
    
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/config/web-app-context.xml
                /WEB-INF/config/web-app-ldap.xml
            </param-value>
        </context-param>
    
        <listener>
            <listener-class>
                org.springframework.web.context.ContextLoaderListener
            </listener-class>
        </listener>
    
        <listener>
            <listener-class>
                org.springframework.web.context.request.RequestContextListener
            </listener-class>
        </listener>
    
        <servlet>
            <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    
            <servlet-class>
                org.springframework.web.servlet.DispatcherServlet
            </servlet-class>
    
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value></param-value>
            </init-param>
    
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    
            <url-pattern>/spring/*</url-pattern>
        </servlet-mapping>
    
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

  3. #3

    Default

    Its started working after adding listener element in my web.xml.
    Thanks for your reply.

Posting Permissions

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