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

转自:https://blog.csdn.net/qq_23184291/article/details/78086398


配置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 导致都不能正常加载,爆错,而你在配置时明明没有使用到缓存,却老是报一个缓存的错误,实在很懵逼。

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

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


<?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>
阅读更多

No bean named 'shiroFilter' is defined

04-22

要把shiro整合进入spring,出现了这个错误,'shiroFilter' 这个bean已经定义过了的,着急在线等。。nn严重: Exception starting filter shiroFilternorg.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'shiroFilter' is definednnnweb.xmlnnn```n nnnn contextClassn n org.springframework.web.context.support.AnnotationConfigWebApplicationContextn nnn n contextConfigLocationn classpath:applicationContext.xml,spring-shiro.xmln nn nn n n n shiroFiltern org.springframework.web.filter.DelegatingFilterProxyn n targetFilterLifecyclen truen n nn n shiroFiltern *.don n n shiroFiltern *.jspn n n n n encodingFiltern org.springframework.web.filter.CharacterEncodingFiltern n encodingn utf-8n n n n encodingFiltern /*n n n n n org.springframework.web.util.Log4jConfigListenern n n n org.springframework.web.context.ContextLoaderListenern n n n n cn.edu.bzu.group4.stockplus.common.base.controller.ApplicationConfigurationFiltern n n n nn n springservletn org.springframework.web.servlet.DispatcherServletn n contextConfigLocationn classpath:applicationContext-servlet.xmln n n n n springservletn /n nn n 404n /404n n n n nn```nspring-shiro.xmlnnn```n nnn Shiron n n n n n n n /login.jsp* = anonn /login.do* = anonn /index.jsp*= anonn /error/noperms.jsp*= anonn /*.jsp* = authcn /*.do* = authcn n n nn n n nn nn n n n n nn n n nn nn```napplicationContext.xmlnnn```n nnn n nn n n n n n n n nn nn n n n n n cn.edu.bzu.group4.stockplus.*n n n n n n org.hibernate.dialect.MySQL5Dialectn truen truen n n n n n n n n n n n n n n n nnn n n n n n n n n n n n n n n n n n n nn n n n n n nnnnn```nnnn

No bean named '' is defined

07-29

在eclipse的控制台启动tomcat后,tomcat正常运行,可是通过tomcat访问页面时,tomcat报如下的错误信息:rn信息: Server startup in 11766 msrn2007-7-29 22:29:33 org.apache.catalina.core.ApplicationContext logrn信息: HTMLManager: init: Associated with Deployer 'Catalina:type=Deployer,host=localhost'rn2007-7-29 22:29:33 org.apache.catalina.core.ApplicationContext logrn信息: HTMLManager: init: Global resources are availablern2007-7-29 22:29:33 org.apache.catalina.core.ApplicationContext logrn信息: HTMLManager: list: Listing contexts for virtual host 'localhost'rn2007-7-29 22:29:36 org.apache.catalina.core.ApplicationContext logrn信息: HTMLManager: list: Listing contexts for virtual host 'localhost'rn 2007-07-29 22:29:37 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/spring].[jsp]] - rnorg.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '' is definedrn at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:360)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:686)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:219)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:149)rn at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:541)rn at org.acegisecurity.util.FilterChainProxy.obtainAllDefinedFilters(FilterChainProxy.java:221)rn at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:136)rn at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)rn at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)rn at java.lang.Thread.run(Thread.java:595)rnrn向高手请指教错误的原因!

No bean named 'sessionFactory' is defined

08-10

2015/08/10 04:50:37.801 [DEBUG] org.springframework.web.context.support.XmlWebApplicationContext[initMessageSource]- Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@6f4cc38]rn2015/08/10 04:50:37.810 [DEBUG] org.springframework.web.context.support.XmlWebApplicationContext[initApplicationEventMulticaster]- Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@6a5b669c]rn2015/08/10 04:50:38.053 [ERROR] org.springframework.web.context.ContextLoader[initWebApplicationContext]- Context initialization failedrn[color=#FF0000]org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined[/color]rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)rn at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)rn at org.apache.catalina.startup.HostConfig.reload(HostConfig.java:1503)rn at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1479)rn at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1665)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:328)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)rn at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)rn at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1546)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1556)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1524)rn at java.lang.Thread.run(Thread.java:745)rnCaused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is definedrn at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)rn at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:435)rn at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)rn at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)rn at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:156)rn at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)rn at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)rn ... 27 morern八月 10, 2015 4:50:38 下午 org.apache.catalina.core.StandardContext listenerStartrn严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerrnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is definedrn at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)rn at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)rn at org.apache.catalina.startup.HostConfig.reload(HostConfig.java:1503)rn at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1479)rn at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1665)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:328)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)rn at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)rn at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1546)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1556)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1524)rn at java.lang.Thread.run(Thread.java:745)rnCaused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is definedrn at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)rn at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:435)rn at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)rn at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)rn at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:156)rn at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)rn at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)rn ... 27 morern八月 10, 2015 4:50:38 下午 org.apache.catalina.core.StandardContext startInternalrn严重: Error listenerStartrn八月 10, 2015 4:50:38 下午 org.apache.catalina.core.StandardContext startInternalrn严重: Context [/finance] startup failed due to previous errorsrn八月 10, 2015 4:50:38 下午 org.apache.catalina.core.ApplicationContext logrn信息: Closing Spring root WebApplicationContextrn

openSessionInViewFilter报No bean named 'sessionFactory' is defined错误

10-12

我是使用注解配置spring的。配置sessionfactory的代码如下rn[code=java]/**rn * 数据源beanrn */rn @Beanrn public DataSource getDataSource() rn BasicDataSource basicDataSource = new BasicDataSource();rn basicDataSource.setDriverClassName(driverName);rn basicDataSource.setUsername(username);rn basicDataSource.setPassword(pwd);rn basicDataSource.setUrl(databaseUrl);rn basicDataSource.setInitialSize(init_size);rn basicDataSource.setMaxActive(maxActive);rn basicDataSource.setMaxIdle(maxIdle);rn basicDataSource.setMaxWait(maxWait);rn return basicDataSource;rn rn rn @Bean(name="sessionFactory")rn public LocalSessionFactoryBean getSessionFactory(DataSource ds)rn LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean();rn lsfb.setDataSource(ds);rn lsfb.setPackagesToScan("mysql.model");rn Properties hibernateProperties = pl.getProperties();rn lsfb.setHibernateProperties(hibernateProperties);rn return lsfb;rn rn rn @Autowiredrn @Bean(name="transactionManager")rn public HibernateTransactionManager getHibernateTransactionManager(SessionFactory sessionFactory)rn HibernateTransactionManager htm = new HibernateTransactionManager(sessionFactory);rn return htm;rn [/code]rn我命名的LocalSessionFactoryBean 的名称为sessionFactoryrn但是我在web.xml配置的openSessionInViewFilter总是报错,web.xml配置如下rn[code=text]rnrnrn Archetype Created Web Applicationrn rn rn openSessionInViewFilterrn rn org.springframework.orm.hibernate5.support.OpenSessionInViewFilterrn rn rn sessionFactoryBeanNamern sessionFactoryrn rn rn singleSessionrn truern rn rn rn openSessionInViewFilterrn /*rn rn rn[/code]rn我手动输出了一下spring的bean列表,发现有sessionFactory的bean,为什么openSessionInViewFilter就是提示找不到呢?求大牛解答

没有更多推荐了,返回首页