spring和springmvc中,Configuration注解Bean重复加载
问题:bean重复加载
1.如下代码所示,开启Configuration注解,实现Bean代码注入,发现bean重复加载
@Configuration
public class EhCacheConfig { @Bean(name="cacheManagerFactoryBean")
public EhCacheManagerFactoryBean ehCacheManagerFactoryBean(){
EhCacheManagerFactoryBean cacheManagerFactoryBean = new EhCacheManagerFactoryBean();
cacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
cacheManagerFactoryBean.setShared (true);
return cacheManagerFactoryBean;
} @Bean(name="ehCacheFactoryBean")
public EhCacheFactoryBean ehCacheFactoryBean(){
EhCacheFactoryBean ehCacheFactoryBean = new EhCacheFactoryBean();
ehCacheFactoryBean.setCacheManager(ehCacheManagerFactoryBean().getObject());
ehCacheFactoryBean.setCacheName("accountCacheName");
return ehCacheFactoryBean;
} @Bean(name="cache")
public Cache cache(){
EhCacheCache cache = new EhCacheCache(ehCacheFactoryBean().getObject());
return cache;
}
}
2.spring.xml扫描配置
<context:component-scan base-package="com.bsoft.platform" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>
3.spring-mvc扫描配置
<context:component-scan base-package="com.bsoft.platform" use-default-filters="true">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
4.解决:
在spring-mvc上加上exclude-filter,排除不需要扫描的注解,代码如下所示
<context:component-scan base-package="com.bsoft.platform" use-default-filters="true">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.context.annotation.Configuration" />
</context:component-scan>
或者这样排除springmvc不需要扫描的类
		<context:exclude-filter type="regex" expression="com\.bsoft\.platform..*Config" />
spring和springmvc中,Configuration注解Bean重复加载的更多相关文章
- Spring源码之@Configuration注解解析
		
1.前言  Spring注解开发中,我们只需求要类上加上@Configuration注解,然后在类中的方法上面加上@Bean注解即可完成Spring Bean组件的注册.相较于之前的xml配置文件定 ...
 - SSM-SpringMVC-14:SpringMVC中大话注解式开发基础--呕心沥血版
		
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 注解的基础我不再多啰嗦,百度一搜很多,很详细啊,我就讲一下SpringMVC中的注解入门 通过注解的方式定义 ...
 - SpringMVC 中 @ControllerAdvice 注解
		
SpringMVC 中 @ControllerAdvice 注解 1.@ControllerAdvice 1.1 全局异常处理 1.2 全局数据绑定 1.3 全局数据预处理 原文地址: 江南一点雨:S ...
 - Spring同一个类中的注解方法调用AOP失效问题总结
		
public interface XxxService { // a -> b void a(); void b(); } @Slf4j public class XxxServiceImpl ...
 - Spring|SpringMVC中的注解
		
文章目录 一.Spring注解 @Controller @ResuController @Service @Autowired @RequestMapping @RequestParam @Model ...
 - Spring和SpringMVC的常用注解
		
Spring的部分: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). <context:component-scan base-package=" ...
 - 【Spring】SpringMVC之基于注解的实现SpringMVC+MySQL
		
目录结构: contents structure [-] SprinigMVC是什么 SpringMVC工作原理 @Controller和@RequestMapping注解 @Controller注解 ...
 - 注解和注释以及Spring和SpringMVC常用的注解
		
1.两者区别 注解 :参与代码编译,以@开头的.它是给应用程序看的,单独使用注解毫无意义,一定要跟工具一起使用,这个所谓的工具实际就是能读懂注解的应用程序 注释 :对代码没有影响.对代码起到解释.说明 ...
 - 【Spring】SpringMVC中浅析Date类型数据的传递
		
在控制器中加入如下代码: @InitBinder public void initBinder(ServletRequestDataBinder bin){ SimpleDateFormat sdf ...
 
随机推荐
- Codeforces Round #442 (Div. 2) Danil and a Part-time Job
			
http://codeforces.com/contest/877/problem/E 真的菜的不行,自己敲一个模板,到处都是问题.哎 #include <bits/stdc++.h> u ...
 - (3)unity3d 地形
			
在Hierarchy(层次) 建一个Terrain(地形) Terrain属性按钮 第一个按钮:抬升与下陷地面.单击抬升地形,同时按住shift下陷地形 第二个按钮:绘制高度.同时按住shift绘制等 ...
 - [转]IIS7.5优化--提高线程数来适应高并发
			
根据压测结果做出的修改历史: 第一步:只针对maxWorkerThreads.maxIoThreads和minWorkerThreads做了修改<processModel autoConfig= ...
 - codevs——1008 选数
			
1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 已知 n ...
 - cmake ccmake
			
下载libqrencode源码编译过程 git clone https://github.com/fukuchi/libqrencode.git 2001 mkdir build 2002 cd ...
 - Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度
			
原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...
 - BZOJ 2131 [scoi2010] 传送带
			
@(BZOJ)[三分法] Description 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段. 两条传送带分别为线段AB和线段CD. lxhgww在AB上的移动速度为P,在CD上的移 ...
 - Java Static Import的用法
			
在头部使用的imoirt static ***方式叫做静态引入,在Java SE 1.5.0(JDK 5)引入的特性. 官方文档的介绍: 为了访问静态成员,有必要限定它们来自的类的引用.例如,必须这样 ...
 - Maven转换成Eclipse/Idea/MyEclipse工程,以及配置Web工程
			
Eclipse/MyEclipse: //Jar mvn eclipse:eclipse mvn eclipse:myeclipse //Web mvn eclipse:eclipse -Dwtpve ...
 - 四个很好的开源app项目
			
Open Source and the iOS App Store Today, we are open-sourcing 4 iOS apps: ThatInbox, an email client ...