1

The following are my configuration file i configured

WEB-INF/classes/applicationContext.xml but it searching for WEB-INF/applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter_anil" version="2.4" 
         xmlns="http://java.sun.com/xml/ns/j2ee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Anil-Spring</display-name>
    <!-- Servlets -->
    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>WEB-INF/classes/applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <!-- Listeners -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>

i am getting following exception

EVERE: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

here is my applicationContext

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
    <import resource="config/controllers.xml" />
    <!-- <import resource="conf/spring/services.xml" />
    <import resource="conf/spring/persistence.xml" />
    <import resource="conf/spring/daos.xml" />
    <import resource="conf/spring//interceptors.xml" /> -->
</beans>

the solution for this is

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter_anil" version="2.4" 
         xmlns="http://java.sun.com/xml/ns/j2ee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Anil-Spring</display-name>
    <!-- Servlets -->
    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
        </init-param> 
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

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

    <!-- Listeners -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>

WARNING: No mapping found for HTTP request with URI [/AnilsSpring/WEB-INF/jsp/hello.jsp] in DispatcherServlet with name 'mvc-dispatcher' please guide line me once

davidfmatheson
  • 3,539
  • 19
  • 27
ravula's
  • 62
  • 1
  • 6

6 Answers6

1

Why is your applicationContext is in the classes? Move it to the WEB-INF directory, as it is told in the comment. That should fix the problem.

The /classes directory is for the compiled classes, but not for the configuration files.

user
  • 3,058
  • 23
  • 45
0

Try adding a / in /WEB-INF/classes/applicationContext.xml

If it still doesn't work, try adding this instead in your web.xml (before the servlet declaration)

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/classes/applicationContext.xml
    </param-value>
</context-param>
Majid Laissi
  • 19,188
  • 19
  • 68
  • 105
  • java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml] i got this to avoid that only i configured above init param – ravula's May 21 '13 at 13:33
  • why it is serching /WEB-INF/applicationContext.xml eventhogh in configured context config location – ravula's May 21 '13 at 13:40
0
<?xml version="1.0" encoding="UTF-8"?>

<web-app id="starter_anil" version="2.4" 
         xmlns="http://java.sun.com/xml/ns/j2ee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Anil-Spring</display-name>
        <!-- Servlets -->
   <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
       </init-param> 
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

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



    <!-- Listeners -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>





</web-app>

this made exception less start on tomcat but i am little bit confused

ravula's
  • 62
  • 1
  • 6
0

If that's where you absolutely must have it, try this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter_anil" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Anil-Spring</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value> 
    </context-param>

    <the-rest-of-your-stuff />
</web-app>

You might need a / before applicationContext.xml, but I don't think so.

davidfmatheson
  • 3,539
  • 19
  • 27
0

May be you need to do undeploy. and deploy it. it will work . . it works for me for the exception IOException parsing XML document from ServletContext resource [/WEB-INF/classes/spring application config.xml];

-1

WEB-INF/classes/applicationContext.xml for this requirement, you have to put applicationContext.xml in class path i.e.

If you are using maven then put it in src/main/resources folder, otherwise put in the src folder.

Then you will find it inside WEB-INF/classes

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Ruju
  • 961
  • 1
  • 12
  • 24
  • yes i am using maven it is inside src/main/resources folder only – ravula's May 21 '13 at 13:37
  • why it is serching /WEB-INF/applicationContext.xml eventhogh in configured context config location – ravula's just now edit – ravula's May 21 '13 at 13:40
  • web.xml configuration see here https://github.com/SpringSource/spring-webflow-samples/blob/master/webflow-showcase/src/main/webapp/WEB-INF/web.xml – Ruju May 21 '13 at 14:10
  • No mapping found for HTTP request with URI [/AnilsSpring/WEB-INF/jsp/hello.jsp] in DispatcherServlet with name 'mvc-dispatcher' can u tell me why it throws like that – ravula's May 21 '13 at 15:12
  • you can check here for configuration http://www.mkyong.com/tutorials/spring-mvc-tutorials/ – Ruju May 22 '13 at 06:12
  • hi i build my application from that example see once [link](http://stackoverflow.com/questions/13524215/warning-no-mapping-found-for-http-request-with-uri-projectdemo-web-inf-jsp-re) he also got the same problem – ravula's May 22 '13 at 08:06