Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

Leos Literak :

Ok, I am 500th user asking this question, I read many answers but still having no luck.

parent module pom contains:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.framework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.framework.version}</version>
</dependency>

Child module has maven-jetty-plugin and I run my webapp module with jetty:run.

web.xml defines standard dispatcher module:

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

<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>/</url-pattern>
</servlet-mapping>

I have file dispatcher-servlet.xml under WEB-INF, though start fails with:

FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

What is wrong? Documentation and everybody says that Spring MVC will search for XX-servlet.xml, where XX is name of servlet. Why does it search for applicationContext.xml?

gerrytan :

ContextLoaderListener has its own context which is shared by all servlets and filters. By default it will search /WEB-INF/applicationContext.xml

You can customize this by using

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/somewhere-else/root-context.xml</param-value>
</context-param>

on web.xml, or remove this listener if you don't need one.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Could not open ServletContext resource

spring boot FileNotFoundException: Could not open ServletContext resource [/WEB-INF/main-servlet.xml]

Spring Boot exception: Could not open ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml]

java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

FileNotFoundException : Could not open ServletContext resource [/WEB-INF/spring/root-context.xml]

Could not open ServletContext resource -- except there is no reference to the resource

nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml]

"Could not open ServletContext resource" in test context

Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/applicationContext.xml]

Spring+ MyBatis+ mvn Project , java.io.FileNotFoundException: Could not open ServletContext resource [/classpath*:WEB-INF/myBatis-config.xml]

Error Could not open ServletContext resource in jUnit Testing Spring Integration

Integration Test - Could not Open ServletContext Resource /application/properties

Could not open ServletContext resource [/<NONE>] when upgrade spring-boot-actuator 1.2.5.RELEASE

Parsing of XML ServletContext resource BeanDefinitionStoreException

Invalid bean definition with name 'offlineTokenServices' defined in ServletContext resource [/WEB-INF/spring-security.xml]

Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/hibernateContext.xml]

Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/applicationContext.xml]:

Spring MVC - Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml];

Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-mvc-crud-demo-servlet.xml]:

Error creating bean with name 'hibernate4AnnotatedSessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]:

No URL for ServletContext resource [/WEB-INF/layouts/layouts.xml] when I run spring-boot with java -jar File.jar

Resource ServletContext resource does not exist

Java could not find XML resource bundle

Spring Framework 4.0.3 BeanDefinitionStoreException Unexpected exception parsing XML document from ServletContext resource

Could not open file [TESTXML.xml]

Open a CRM Entity from a Web Resource

Gradle publishPubNamePublicationToRepoNameRepository fails with "Could not get resource [...] maven-metadata.xml"

WildFly Could not find resource for full path (no XML, using commandline deployment)

Could not parse mapping document from resource Books.hbm.xml