springmvc运行时出现NoSuchBeanDefinitionException异常
检测异常信息是否出现如下信息:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0':
Cannot resolve reference to bean 'cacheManager' while setting bean property 'cacheManager';
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cacheManager' is defined
如果是以上异常,,spring配置文件添加注解扫描<mvc:annotation-driven />之后,idea会自动给你添加引用
xmlns:mvc="http://www.springframework.org/schema/cache",所以会报错。
解决办法:
把原来的引用删除
xmlns:mvc="http://www.springframework.org/schema/cache"
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd
再添加如下xmlns:
xmlns:mvc="http://www.springframework.org/schema/mvc"
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
当你在运行项目时,问题已解决。
引自:https://blog.csdn.net/weixin_40086687/article/details/87352993