使用Idea構建springmvc框架,出現no bean named 'cacheManager' is defined 錯誤
使用Idea構建springmvc框架,出現no bean named ‘cacheManager’ is defined 錯誤。
不可否認IDEA確實是最好的java開發軟體,各種提示智慧的有點非人類,整合的git也很強大,git命令幾乎都不需要敲啦,介面也比較美觀。。。:
但也是由於提示太多啦也導致一堆的問題:
下面是我構建springmvc的步驟:其中就是由於一個不注意,產生一大波錯誤困擾我好久好久……
- 首先建立一個maven專案,在pom檔案中新增依賴的jar包
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.seaOf</groupId>
<artifactId>spring-mvc</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>spring-mvc Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!--Junit4測試包-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!--spring-ioc&di start-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<!--spring-ioc&di end-->
<!--spring AOP start-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.4</version>
</dependency>
<!--spring AOP end-->
<!--sping jdbc整合 start-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<!-- spring 事務控制 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<!--sping jdbc整合 end-->
<!--spring -mvc start-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<!--spring -mvc end-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13-atlassian-2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
groupId>javax.inject/groupId>
<artifactId>com.springsource.javax.inject</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<finalName>spring-mvc</finalName>
</build>
這個是所以的依賴,我這主要是出錯啦 為防止意外所以
以相關的包都匯入啦。
2. 配置springmvc-servlet.xml檔案,配置好包掃描,mvc註解,及檢視解釋配置
由於IDEA的自動補全功能非常強大,當你配置 <mvc:annotation-driven/>
後編譯器會幫你自動補全上面兩個配置檔案約束。這個時候如果你沒注意的就會爆出一個很莫名奇妙的錯:
- 上面主要爆這個錯:九月 25, 2017 8:40:23 上午 org.apache.catalina.core.ApplicationContext log
資訊: Initializing Spring FrameworkServlet ‘springmvc’
九月 25, 2017 8:40:23 上午 org.apache.catalina.core.ApplicationContext log
嚴重: StandardWrapper.Throwable
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
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329).getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)。
報錯原因是:Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘cacheManager’ is defined
這裡主要是因為上面springmvc-servlet.xml配置檔案中由於IDEA自動配置啦cache,但配置檔案中又沒有指定快取的空間,JVM虛擬機器中也有個cacheManage,這就導致spring進行bean管理時掃描到兩個cache Manage 導致都不能正常載入,爆錯,而你在配置時明明沒有使用到快取,卻老是報一個快取的錯誤,實在很懵逼。
解決辦法
正確的配置檔案是這個樣子的
<?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/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="controller"/>
<mvc:annotation-driven/>
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
相關文章
- 使用Idea構建springmvc框架,出現no bean named ‘cacheManager’ is defined 錯誤。IdeaSpringMVC框架Bean
- SpringMVC莫名其妙出現No bean named 'cacheManager' is defined錯誤SpringMVCBean
- 記一次idea構建springmvc報錯:No bean named 'cacheManager' availableIdeaSpringMVCBeanAI
- No bean named 'xxx' is defined錯誤,原因及解決方案Bean
- 報錯No bean named ' is defined的原因和解決方案Bean
- No bean named 'cacheManager' availablej 異常解決BeanAI
- spring getBean(String) No bean named '' is definedSpringBean
- 使用@Service註解出現No bean named 'xxxx' available]錯誤BeanAI
- 報錯:org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xxx'is definedSpringFrameworkBeanException
- spring中No bean named xxx available錯誤SpringBeanAI
- ant構建時出現錯誤解決方案
- 編譯實體Bean出現如下錯誤.....編譯Bean
- idea maven搭建spring報錯:No bean named 'xxx' availableIdeaMavenSpringBeanAI
- 關於idea使用SpringMVC框架訪問WEB-INF中的檔案出現404報錯IdeaSpringMVC框架Web
- DBCA建庫出現CHMOD NOT FOUND錯誤
- 使用 sudo 命令出現錯誤
- Intellij IDEA使用@Autowired註解,出現could not autowire錯誤,解決方案IntelliJIdea
- 使用JBoss部署實體Bean,資料庫是oracle9i,出現錯誤,求助!!!Bean資料庫Oracle
- No Bean named 'Xxx' available 異常報錯BeanAI
- No bean named BookServiceImpl availableBeanAI
- springMVC資料驗證出現404錯誤解決辦法SpringMVC
- GetDlgItem() 出現錯誤Git
- 使用idea搭建springMVCIdeaSpringMVC
- Spring:錯誤No bean named 'xxxxxxx' availableSpringBeanAI
- SpringMVC錯誤記錄SpringMVC
- Ubuntu20.04安裝LabelImg 以及出現(ModuleNotFoundError: No module named libs.resources)錯誤UbuntuError
- Opencv出現detecMultiScale錯誤OpenCV
- No bean named ''XXX“ availableBeanAI
- spring配置檔案中配置了,但找不到Bean , 啟動不報錯,執行報錯No bean namedSpringBean
- 幽默:使用錯誤框架的下場框架
- springboot註解實現非同步呼叫時no bean of type TaskExecutor and no bean named 'taskExecutor' eitherSpring Boot非同步Bean
- 關於idea中使用註解開發springmvc 500報錯IdeaSpringMVC
- Laravel 出現 419 錯誤Laravel
- AS打包出現app:transformClassesAndResourcesWithProguardForRelease錯誤APPORM
- FTP出現426錯誤FTP
- [轉載]使用IntelliJ IDEA開發SpringMVC網站(二)框架配置IntelliJIdeaSpringMVC網站框架
- ORACLE 使用DBCA安裝資料庫出現錯誤Oracle資料庫
- pip安裝錯誤:ImportError: No module named 'pkg_resources'ImportError