报错信息
03-Jul-2020 19:19:52.558 警告 [RMI TCP Connection(3)-127.0.0.1] org.springframework.context.support.AbstractApplicationContext.refresh Exception encountered during context initialization - cancelling refresh attempt: 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' available
03-Jul-2020 19:19:52.562 严重 [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed
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' available
...
03-Jul-2020 19:19:52.576 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
03-Jul-2020 19:19:52.577 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [/SpringMVC] startup failed due to previous errors
[2020-07-03 07:19:52,590] Artifact SpringMVC:war exploded: Error during artifact deployment. See server log for details.
03-Jul-2020 19:20:00.379 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [D:\apache-tomcat-9.0.31\webapps\manager]
03-Jul-2020 19:20:00.433 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:\apache-tomcat-9.0.31\webapps\manager] has finished in [54] ms
错误提示 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’ available
在设置bean属性“cacheManager”时无法解决对bean“cacheManager”的引用。 经过百度得知cacheManager适用于缓存的,但此时并未配置缓存相关的信息。 但是在检查xml配置文件时,发现beans标签中有一条 xmlns:mvc=“http://www.springframework.org/schema/cache” 对应的schemaLocation也有 http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd" 可以发现本应是配置mvc标签的位置变为了配置cache标签,导致<mvc:annotation-driven/>虽然没报错,但在运行时,无法找到对应的资源。 经过重试几次后发现IDEA在配置mvc标签时,自动生成的xmlns及schemaLocation会生成为cache的,这时只需将其改为mvc或添加mvc的即可。
错误标签
<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 https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
改正标签如下:
<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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">