无法为bean找到类[org.springframework.web.servlet.view.InternalResourceViewResolver]

时间:2014-01-07 06:11:16

标签: java spring spring-mvc servlets

我正在尝试使用注释获得简单的spring应用程序,但是在运行应用程序时我遇到异常......

  

严重:上下文初始化失败   org.springframework.beans.factory.CannotLoadBeanClassException:找不到ServletContext资源中定义名为'viewResolver'的bean的类[org.springframework.web.servlet.view.InternalResourceViewResolver] [/WEB-INF/mvc-dispatcher-servlet.xml ]。嵌套异常是java.lang.ClassNotFoundException:org.springframework.web.servlet.view.InternalResourceViewResolver       在org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1275)       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:575)       在org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1344)       在org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:910)       at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)       在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)       在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)       at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)       在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)       在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)       在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)       at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)       在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1566)       在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1556)       at java.util.concurrent.FutureTask $ Sync.innerRun(Unknown Source)       at java.util.concurrent.FutureTask.run(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)       在java.lang.Thread.run(未知来源)   引起:java.lang.ClassNotFoundException:org.springframework.web.servlet.view.InternalResourceViewResolver       在org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)       在org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)       在org.springframework.util.ClassUtils.forName(ClassUtils.java:260)       在org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:416)       在org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1296)       在org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1267)       ......还有19个

我的文件是 -

的web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="2.5"
xmlns="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" >

<display-name>SpringTest</display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

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

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>

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

调度-servlet.xml中

       `    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
  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">

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

    <property
        name="suffix"
        value=".jsp" />
</bean>

 <context:component-scan base-package="com.controller" />

`

我在WEB-INF

下的lib文件夹中添加了以下jar

共享记录-1.1.2.jar,     org.springframework.aop-3.0.5.RELEASE.jar,     org.springframework.asm-3.0.5.RELEASE.jar,     org.springframework.aspects-3.0.5.RELEASE.jar,     org.springframework.beans-3.0.5.RELEASE.jar,     org.springframework.context.support-3.0.5.RELEASE.jar,     org.springframework.context-3.0.5.RELEASE.jar,     org.springframework.core-3.0.5.RELEASE.jar,     org.springframework.expression-3.0.5.RELEASE.jar,     org.springframework.transaction-3.0.5.RELEASE.jar,     org.springframework.web.servlet-3.0.5.RELEASE.jar,     org.springframework.web-3.0.5.RELEASE.jar

我不确定为什么会这样,所以请帮助我。

我通过从服务器中删除其他项目来修复此问题

2 个答案:

答案 0 :(得分:1)

将spring-webmvc jar添加到classpath

答案 1 :(得分:-1)

只需更改spring框架的版本即可。 使用版本4.1.5.RELEASE jar