org.springframework.beans.factory.BeanCreationException:创建名称为 'org.springframework.cache.interceptor.CacheInterceptor#0' 的 bean 时出错

org.springframework.beans.factory.BeanCreationException: error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0'

我是 java Spring 的初学者 我尝试创建简单的 hello world 应用程序,当我 运行 它给我这个错误 这是我的错误消息 我尝试了一切我可以。
我已经更改了 url-pattern 但是当我将文件保存在 web-inf 文件夹下时它不会起作用。

我遇到了一个异常,根本原因如下:

org.springframework.beans.factory.BeanCreationException: error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0'

我的控制器

 package com.dare.controller.home;
 import org.springframework.stereotype.Controller; 
 import org.springframework.web.bind.annotation.RequestMapping;

 @Controller public class controller {
   @RequestMapping("/home")
   public String home(){
         return "home";
      } 
 }

我的 dispatcher-servlet

<?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:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/cache"
       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 http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
    <context:component-scan base-package="com.dare"/>
    <mvc:annotation-driven />
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">    
        <property name="prefix" value="/WEB-INF/view"/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

WEB.XML 文件

 <?xml version="1.0" encoding="UTF-8"?>  <web-app
 xmlns="http://xmlns.jcp.org/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"          version="3.1">
    <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>/</url-pattern>
    </servlet-mapping>  </web-app>

PROM.XML 文件

<?xml version="1.0" encoding="UTF-8"?> 
<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>ill</groupId>
<artifactId>ill</artifactId>
<version>1.0-SNAPSHOT</version> 
 <dependencies>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc  -->
   <dependency>
         <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.3.6.RELEASE</version>
      </dependency>
    <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
     <dependency>
        <groupId>javax.servlet</groupId>
         <artifactId>jstl</artifactId>
         <version>1.2</version>
     </dependency>
     <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-webmvc</artifactId>
         <version>4.3.6.RELEASE</version>
      </dependency>
   </dependencies>
 </project>

查看文件

   <%--   Created by IntelliJ IDEA.   User: dare   Date: 12/24/2017  
   Time: 1:27 PM   To change this template use File | Settings | File
   Templates.  --%> 
   <%@ page contentType="text/html;charset=UTF-8" language="java" %> 
   <html>   
    <head><title>Title</title> </head> 
    <body> <h1>Hi hello</h1> </body> 
   </html>

堆栈跟踪表明没有 cacheManager。您需要通过将此添加到您的 spring xml 配置来告诉 spring 初始化 cacheManager

<cache:annotation-driven/>

有关详细信息,请参阅 https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/cache/annotation/EnableCaching.html