使用Idea构建springmvc框架,出现no bean named 'cacheManager' is defined 错误

使用Idea构建springmvc框架,出现no bean named ‘cacheManager’ is defined 错误。

不可否认IDEA确实是最好的java开发软件,各种提示智能的有点非人类,集成的git也很强大,git命令几乎都不需要敲啦,界面也比较美观。。。:

但也是由于提示太多啦也导致一堆的问题:
下面是我构建springmvc的步骤:其中就是由于一个不注意,产生一大波错误困扰我好久好久……

  1. 首先创建一个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.0modelVersion>

  <groupId>me.seaOfgroupId>

  <artifactId>spring-mvcartifactId>

  <packaging>warpackaging>

  <version>1.0-SNAPSHOTversion>

  <name>spring-mvc Maven Webappname>

  <url>http://maven.apache.orgurl>

  <dependencies>

    

    <dependency>

      <groupId>junitgroupId>

      <artifactId>junitartifactId>

      <version>4.12version>

      <scope>testscope>

    dependency>



    

      <dependency>

        <groupId>org.springframeworkgroupId>

        <artifactId>spring-coreartifactId>

        <version>3.2.3.RELEASEversion>

      dependency>

      <dependency>

        <groupId>org.springframeworkgroupId>

        <artifactId>spring-beansartifactId>

        <version>3.2.3.RELEASEversion>

      dependency>

      <dependency>

        <groupId>org.springframeworkgroupId>

        <artifactId>spring-contextartifactId>

        <version>3.2.3.RELEASEversion>

      dependency>

      <dependency>

        <groupId>org.springframeworkgroupId>

        <artifactId>spring-context-supportartifactId>

        <version>3.2.3.RELEASEversion>

      dependency>

      <dependency>

        <groupId>org.springframeworkgroupId>

        <artifactId>spring-expressionartifactId>

        <version>3.2.3.RELEASEversion>

      dependency>

    

    

    <dependency>

      <groupId>org.springframeworkgroupId>

      <artifactId>spring-aopartifactId>

      <version>3.2.3.RELEASEversion>

    dependency>

    <dependency>

      <groupId>org.springframeworkgroupId>

      <artifactId>spring-aspectsartifactId>

      <version>3.2.3.RELEASEversion>

    dependency>

      <dependency>

        <groupId>aopalliancegroupId>

        <artifactId>aopallianceartifactId>

        <version>1.0version>

      dependency>

      <dependency>

        <groupId>org.aspectjgroupId>

        <artifactId>aspectjrtartifactId>

        <version>1.7.4version>

      dependency>

      <dependency>

        <groupId>org.aspectjgroupId>

        <artifactId>aspectjweaverartifactId>

        <version>1.7.4version>

      dependency>

    

    

    <dependency>

      <groupId>org.springframeworkgroupId>

      <artifactId>spring-jdbcartifactId>

      <version>3.2.3.RELEASEversion>

    dependency>

    <dependency>

      <groupId>org.springframeworkgroupId>

      <artifactId>spring-testartifactId>

      <version>3.2.3.RELEASEversion>

    dependency>

    

    <dependency>

      <groupId>org.springframeworkgroupId>

      <artifactId>spring-txartifactId>

      <version>3.2.3.RELEASEversion>

    dependency>

    

    

    <dependency>

      <groupId>org.springframeworkgroupId>

      <artifactId>spring-webartifactId>

      <version>3.2.3.RELEASEversion>

    dependency>

    <dependency>

      <groupId>org.springframeworkgroupId>

      <artifactId>spring-webmvcartifactId>

      <version>3.2.3.RELEASEversion>

    dependency>



    

    <dependency>

      <groupId>commons-iogroupId>

      <artifactId>commons-ioartifactId>

      <version>2.0.1version>

    dependency>

    <dependency>

      <groupId>commons-logginggroupId>

      <artifactId>commons-loggingartifactId>

      <version>1.0.4version>

    dependency>

    <dependency>

      <groupId>commons-fileuploadgroupId>

      <artifactId>commons-fileuploadartifactId>

      <version>1.2.2version>



    dependency>

    <dependency>

      <groupId>org.hibernategroupId>

      <artifactId>hibernate-validatorartifactId>

      <version>4.1.0.Finalversion>

    dependency>

    <dependency>

      <groupId>org.codehaus.jacksongroupId>

      <artifactId>jackson-core-aslartifactId>

      <version>1.9.13-atlassian-2version>

      <type>pomtype>

    dependency>

    <dependency>

      <groupId>org.codehaus.jacksongroupId>

      <artifactId>jackson-mapper-aslartifactId>

      <version>1.9.13version>

    dependency>

    <dependency>

      <groupId>javax.servlet.jsp.jstlgroupId>

      <artifactId>jstl-apiartifactId>

      <version>1.2version>

    dependency>

    <dependency>

      <groupId>org.glassfish.webgroupId>

      <artifactId>jstl-implartifactId>

      <version>1.2version>

    dependency>

    <dependency>

      <groupId>org.slf4jgroupId>

      <artifactId>slf4j-apiartifactId>

      <version>1.5.8version>

    dependency>

    <dependency>

groupId>javax.inject/groupId>

      <artifactId>com.springsource.javax.injectartifactId>

      <version>1.0.0version>

    dependency>

  dependencies>

  <build>

    <finalName>spring-mvcfinalName>

  build>

这个是所以的依赖,我这主要是出错啦 为防止意外所以
以相关的包都导入啦。
2. 配置springmvc-servlet.xml文件,配置好包扫描,mvc注解,及视图解释配置
注意用黑框标注出来的部分
由于IDEA的自动补全功能非常强大,当你配置
后编译器会帮你自动补全上面两个配置文件约束。这个时候如果你没注意的就会爆出一个很莫名奇妙的错:这里写图片描述
- 上面主要爆这个错:九月 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 导致都不能正常加载,爆错,而你在配置时明明没有使用到缓存,却老是报一个缓存的错误,实在很懵逼。

  1. 解决办法
    这里写图片描述

  2. 正确的配置文件是这个样子的



<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>

你可能感兴趣的:(异常处理,随记)