Reputation: 4155
I am developing a simple web application using Spring framework 3.1.3.RELEASE & MAVEN. My application would not startup unless I take out the listener from web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Tomcat reports the following error:
INFO: Deploying web application archive sampleapp.war
11/12/2012 3:45:03 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
11/12/2012 3:45:03 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/sampleapp] startup failed due to previous errors
My WEB.XML looks as follows:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>EMS</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/*-context.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Application Context File is empty at this point:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
</beans>
Below is the JAR files under WEB-INF/lib
eclipselink-2.4.0.jar
javax.persistence-2.0.0.jar
mysql-connector-java-5.1.21.jar
spring-context-3.1.3.RELEASE.jar
spring-core-3.1.3.RELEASE.jar
spring-web-3.1.3.RELEASE.jar
spring-webmvc-3.1.3.RELEASE.jar
Below is the files under WEB-INF
application.properties
spring-context.xml
web.xml
I understand that:
What am I doing wrong?
Upvotes: 0
Views: 4897
Reputation: 4155
The problem was missing Spring Dependencies in my POM file. I initially had the following dependencies in the POM
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
I enabled debugging on tomcat logging.properties to see that I was getting a class ava.lang.NoClassDefFoundError as I added dependencies (one at a time) the ava.lang.NoClassDefFoundError kept changing until all dependencies were satisfied. The ContextLoaderListener started up OK after that. The dependencies I added are:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- required by Spring -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
I
Upvotes: 0
Reputation: 1000
I share duffmo's reasoning, just want to point out, that you can leave the application context in the WEB-INF directory, if you update your config to:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring-context.xml</param-value>
</context-param>
This way your global application context resides in the same directory as the dispatcher configurations.
Upvotes: 1
Reputation: 308998
Here's your problem: Move the spring-context.xml
into WEB-INF/classes
and set the context param as follows:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-context.xml</param-value>
</context-param>
WEB-INF is not in the CLASSPATH.
Upvotes: 4