記一次idea構建springmvc報錯:No bean named 'cacheManager' available

木偶1在哪發表於2019-01-08

 第一次在idea中構建springmvc總是報錯:

後面發現原因竟然是idea的自動提示功能太強大造成的弊端!!!

這裡主要是因為我的spring-mvc.xml配置檔案中由於IDEA自動配置了cache,但配置檔案中又沒有指定快取的空間,JVM虛擬機器中也有個cacheManage,這就導致spring進行bean管理時掃描到兩個cache Manage 衝突導致都不能正常載入,報錯。

我一開始錯誤的spring-mvc.xml

<?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:mvc="http://www.springframework.org/schema/cache"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/cache
       http://www.springframework.org/schema/cache/spring-cache.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!--使用註解來進行請求對映     -->
    <mvc:annotation-driven/>

</beans>

錯誤地方:

修改後的spring-mvc.xml

<?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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       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.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">
<!--使用註解來進行請求對映     -->
<mvc:annotation-driven/>

</beans>

 

相關文章