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 ...
随机推荐
- POJ - 2391 最大流
题目链接:http://poj.org/problem?id=2391 今天掉坑多次. 做了几道题,发现从源点出来的边和进入汇点的边都在题目中出来过. POJ真是坑,交G++一直wa,检查代码检查了好 ...
- jquery鼠标点击窗口或浮动层以外关闭层【阻止冒泡事件】
$(".up-list a.th1").click(function(){ $(this).next("ul#up-list-ul").show(); }); ...
- 洛谷——P2706 巧克力
P2706 巧克力 题目背景 王7的生日到了,他的弟弟准备送他巧克力. 题目描述 有一个被分成n*m格的巧克力盒,在(i,j)的位置上有a[i,j]块巧克力.就在送出它的前一天晚上,有老鼠夜袭巧克力盒 ...
- 洛谷——P3252 [JLOI2012]树
P3252 [JLOI2012]树 题目描述 在这个问题中,给定一个值S和一棵树.在树的每个节点有一个正整数,问有多少条路径的节点总和达到S.路径中节点的深度必须是升序的.假设节点1是根节点,根的深度 ...
- DICOM医学图像处理:深入剖析Orthanc的SQLite,了解WADO & RESTful API
背景: 上一篇博文简单翻译了Orthanc官网给出的CodeProject上“利用Orthanc Plugin SDK开发WADO插件”的博文,其中提到了Orthanc从0.8.0版本之后支持快速查询 ...
- ASP.Net MVC开发基础学习笔记(8):新建数据页面
前言 前面解说了怎样创建一个查询页面并给查询页面加入排序.搜索及分页功能.今天我们来讲讲怎样向这个列表加入数据. 解说的顺序将依照加入数据的步骤的时间顺序来进行,方便大家理清逻辑关系. 本节将涉 ...
- Unity3d载入外部图片文件
unity里的图片在生成时会压缩成资源文件,有时客户想自己放一些图片用unity显示,就必须载入外部图片. 大体思路:用Application.streamingAssetsPath或Applicat ...
- Construct Binary Tree from Inorder and Postorder Traversal ——通过中序、后序遍历得到二叉树
题意:根据二叉树的中序遍历和后序遍历恢复二叉树. 解题思路:看到树首先想到要用递归来解题.以这道题为例:如果一颗二叉树为{1,2,3,4,5,6,7},则中序遍历为{4,2,5,1,6,3,7},后序 ...
- was系统错误日志大量出现标识符缺失
原创作品.出自 "深蓝的blog" 博客,深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/46909941 近日 ...
- Something about cache
http://www.tyut.edu.cn/kecheng1/2008/site04/courseware/chapter5/5.5.htm 5.5 高速缓冲存储器cache 随着CPU时钟速率的不 ...