Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've got the error

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

when deploying only if I include the following piece of code between "Spring Security" and "END Spring Security" in the file web.xml. If I remove this part of the code in the XML everything works fine.

 <?xml version="1.0" encoding="UTF-8"?>
<web-app 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" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
        version="2.5">


 <!-- Spring MVC -->
 <servlet>
 <servlet-name>dispatch</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <load-on-startup>1</load-on-startup>
</servlet>
 <servlet-mapping>
 <servlet-name>dispatch</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

 <servlet>
 <servlet-name>floorOperationWS</servlet-name>
 <servlet- class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
 </servlet>
 <servlet-mapping>
<servlet-name>floorOperationWS</servlet-name>
<url-pattern>/floorOperationWS/*</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>updatefloorServlet</servlet-name>
    <servlet-class>com.services.endpoint.UpdatefloorEventServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>updatefloorServlet</servlet-name>
    <url-pattern>/updatefloorWS</url-pattern>
</servlet-mapping>

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

    <!-- Spring Security -->

     <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring-security.xml
    </param-value>
</context-param>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

    <!-- END Spring Security -->

</web-app>

-- spring-security.xml :

   <beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">

<http auto-config="true">
    <intercept-url pattern="/admin**" access="ROLE_USER" />
</http>

<authentication-manager>
    <authentication-provider>
        <user-service>
            <user name="mkyong" password="123456" authorities="ROLE_USER" />
        </user-service>
    </authentication-provider>
</authentication-manager>

-- MAVEN dependencies:

            <properties>        
    <java-version>1.7</java-version>
    <!--  org.springframework-version>3.0.5.RELEASE</org.springframework-v version-->
    <org.springframework-version>4.0.3.RELEASE</org.springframework-version>
    <spring.security.version>3.2.3.RELEASE</spring.security.version>
    <org.aspectj-version>1.6.10</org.aspectj-version>
    <org.slf4j-version>1.5.10</org.slf4j-version>
    <junit.version>4.11</junit.version>
</properties>
<dependencies>
    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework-version}</version>
        <exclusions>
            <!-- Exclude Commons Logging in favor of SLF4j -->
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
             </exclusion>
        </exclusions>
    </dependency>
    <!-- Spring 3 dependencies -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>

    <!-- Spring Security -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring.security.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${spring.security.version}</version>
    </dependency>

<!-- DB connection -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>

What's causing this error and how can I fix it?

share|improve this question
add comment

3 Answers

Common problem causing this error is wrongly included spring jar You didnt mention your ide so i assume you are using eclipse Solution for this is

1.Double click on server used for deploying

2.Click open Launch configuration - classpath tab

3.Click Add External Jars

4.add spring jar

5.run your application

share|improve this answer
    
Hi, i am using eclipse and the classpath seems to be OK: M2_REPO/org/springframework/spring-core/4.0.3.RELEASE/spring-core-4.0.3.RELEASE.‌​jar –  user2547539 Apr 12 at 12:06
    
Ok you can try one more thing Open the project's properties Then go to deployment assembly ther you have to click Add.. Select Java Build Path Entries from Directive Type menu and click Next. Select Maven Dependencies from Java Build Path Entries and click finish –  Ziker Apr 12 at 12:24
    
Already done :-( –  user2547539 Apr 12 at 12:35
add comment

I have created a sample project with given details two issue I faced :
> Spring security version : 3.2.3.RELEASE
change it to 3.1.6.RELEASE //(although this case should not give an error )
> in given pom you have not added spring-mvc jar
after adding this it works for me

share|improve this answer
    
I've tried with 3.1.6 with the same result, spring-mvc was included as well: <artifactId>spring-webmvc</artifactId> –  user2547539 Apr 12 at 14:34
add comment

changing

 <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
    /WEB-INF/spring-security.xml
</param-value>

for in applicationContext.xml

<import resource="spring-security.xml" />

solved the problem

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.