java.lang.ClassNotFoundException: org.springframework.ui.ModelMap

白昼怎懂夜的黑 提交于 2019-12-14 03:59:59

问题


I create a simple webapp using tomcat 6, spring 2.5.6 and maven.

The problem is when I boot up tomcat, I am getting the following errors:

SEVERE: StandardWrapper.Throwable
java.lang.NoClassDefFoundError: org/springframework/ui/ModelMap
...
Caused by: java.lang.ClassNotFoundException: org.springframework.ui.ModelMap

The ModelMap class does exist in spring-2.5.6.jar and spring-context-2.5.6.jar, I also have some other spring jars. All of them are being deployed to tomcat correctly, when I check the application WEB-INF (deployed to tomcat) I found all those jars there!

I have only one @Controller that has a @RequestMapping("/home.htm") showForm(ModelMap model) method. My applicationContext is quite simple:

<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
              http://www.springframework.org/schema/aop 
              http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-2.5.xsd
              http://www.directwebremoting.org/schema/spring-dwr
              http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"
    default-autowire="byName">

<context:component-scan base-package="org.myapp"/>
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

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

回答1:


spring-2.5.6.jar is the JAR that contains all of the spring framework. If you use that JAR, you should not use any of the other JARs like spring-context-2.5.6.jar. These smaller JARs are there if you want to pick ands choose the bits of Spring that you need.

It's possible that the classloader is getting confused between the duplicate copies of the classes between the JARs. Take out all of the Spring JARs except for spring-2.5.6.jar, and see if that makes a difference.



来源:https://stackoverflow.com/questions/2753464/java-lang-classnotfoundexception-org-springframework-ui-modelmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!