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 ...
随机推荐
- 不要使用 reader.Peek() 去读取每行数据
1.问题描述 使用SteamRead的Peek()和ReadLine()来读取流中的数据,如果数据行数太多,会读取不完整(后面有些数据就读不出来了). 比如: while (srResponseRea ...
- Toast问题记录:This Toast was not created with Toast.makeText()
最近使用自己封装的Toast时,遇到一个问题 java.lang.RuntimeException: This Toast was not created with Toast.makeText() ...
- HDU 4691
http://acm.hdu.edu.cn/showproblem.php?pid=4691 留个板子. #include <iostream> #include <cstdio&g ...
- 济南day4
啥也不会,做了不对,对了没分.T1 50 + 30 + 0想了想,有思路,写了,半个小时写完,算错复杂度,复杂度最差(n*m),想成了(n+m)被卡没了50分,gg.....T2自己写了个单向并查集, ...
- PE 512 Sums of totients of powers
可以很简单的发现,当n是奇数的时候,f(n)=φ(n),否则f(n)=0. 所以我们就是求n<=5*10^8且n为奇数的φ的和. 首先我们可以做到用杜教筛算出φ的前缀和,但是如何把偶数的减去? ...
- 「NOI2014」动物园
link : https://loj.ac/problem/2246 水水KMP #include<bits/stdc++.h> #define ll long long #define ...
- Linux下快速删除输错的密码技巧(快速删除输入的命令)
1.[Esc]+[退格键(Backspace)] 2.[Ctrl]+[U] 说明:以上两个快捷键都会删除全部输错的命令或密码. 参考: http://blog.csdn.net/u013895662/ ...
- Geoserver跨域请求设置
使用OpenLayers请求GeoServer发布的WFS服务时,如果不是相同的域可能会出现如下问题. 已拦截跨源请求:同源策略禁止读取位于 http://localhost:8080/geoserv ...
- Canvas的效果操作及save()和restore()方法应用
平移.缩放.旋转等操作等于是,我在一个正的画布绘制好图,然后再把画布做旋转.平移.缩放等等的效果. 也就是说,我使用的X.Y坐标还是正常的坐标(没旋转.平移.缩放等之前的坐标). save()和res ...
- Git以及github的使用方法(二)创建仓库,git add添加到“暂储区”,git commit添加到“本地仓库”
什么是版本库呢?版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以便任何时刻都可以追踪历史,或 ...