0

When I include the line <mvc:annotation-driven /> in the following

mvc-dispatcher-servlet.xml:

<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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package="com.skyscraper.controller" />
<mvc:annotation-driven />

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
    <property name="prefix">
        <value>/WEB-INF/pages/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>
</beans>

I get the following error:

java.lang.ClassNotFoundException: org.springframework.context.i18n.LocaleContextHolder

when running my application.

POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.skyscraper</groupId>
<artifactId>skyscraper-api</artifactId>
<version>0.1.0-SNAPSHOT</version>

<name>skyscraper-api</
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <my.version>0.1.0</my.version>
</properties><build>

<finalName>ROOT</finalName>

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
    </configuration>
  </plugin>

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
        <execution>
            <goals>
                <goal>install-file</goal>
            </goals>
            <phase>install</phase>
            <configuration>
                <file>${project.build.finalName}.${project.packaging}</file>
                <generatePom>false</generatePom>
                <pomFile>pom.xml</pomFile>
                <version>${my.version}</version>
            </configuration>
        </execution>
      </executions>
  </plugin>
</plugins>
</build>

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>

       <!-- Spring framework --> 
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.0.2.RELEASE</version>
</dependency>

<!-- JSTL --> 
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.1.2</version>
</dependency>

<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>

<!-- for compile only, your container should have this -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

<!-- Jackson JSON -->
<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.7</version>
</dependency>
<dependency> 
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-core-asl</artifactId>
    <version>1.9.7</version>
</dependency>

<!-- Spring Security module --> 
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>3.2.0.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>3.2.0.RELEASE</version>
</dependency>

<dependency>

<groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.0.2.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.0.2.RELEASE</version>
</dependency>
</dependencies>

<packaging>war</packaging>
</project>

Stack Trace

javax.servlet.ServletException: Servlet execution threw an exception

java.lang.NoClassDefFoundError: org/springframework/context/i18n/LocaleContextHolder
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:949)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

java.lang.ClassNotFoundException: org.springframework.context.i18n.LocaleContextHolder
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:949)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

Can I still use <mvc:annotation-driven /> in Spring4 or am I missing something else?

user2035039
  • 961
  • 3
  • 16
  • 30
  • 1
    Please add the actual stack trace and also your dependencies (pom). First fix your xml file you are mixing spring versions (2.5, 3.0, 4.0) in your declarations. It is advised to use the version-less xsd so that you always use the latest versions. – M. Deinum Mar 01 '14 at 13:21
  • i fixed the xml and added my pom – user2035039 Mar 01 '14 at 14:01
  • If you create a war the file should be there, if you use other means to deploy your application it might depend. How do you deploy your application. – M. Deinum Mar 01 '14 at 16:25
  • The file is there now, but I also got a SAXParseException: Could not find declaration for element "mvc:annotation-driven". I deploy my application by copying the generated war-file to tomcats /tomcat/webapps/ folder – user2035039 Mar 01 '14 at 17:28
  • Solved it looking at http://stackoverflow.com/questions/15406231/no-declaration-can-be-found-for-element-mvcannotation-driven. Thanks for the hint with the xsd versions. – user2035039 Mar 01 '14 at 17:39

0 Answers0