问题: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重复加载的更多相关文章

  1. Spring源码之@Configuration注解解析

    1.前言 ​ Spring注解开发中,我们只需求要类上加上@Configuration注解,然后在类中的方法上面加上@Bean注解即可完成Spring Bean组件的注册.相较于之前的xml配置文件定 ...

  2. SSM-SpringMVC-14:SpringMVC中大话注解式开发基础--呕心沥血版

     ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 注解的基础我不再多啰嗦,百度一搜很多,很详细啊,我就讲一下SpringMVC中的注解入门 通过注解的方式定义 ...

  3. SpringMVC 中 @ControllerAdvice 注解

    SpringMVC 中 @ControllerAdvice 注解 1.@ControllerAdvice 1.1 全局异常处理 1.2 全局数据绑定 1.3 全局数据预处理 原文地址: 江南一点雨:S ...

  4. Spring同一个类中的注解方法调用AOP失效问题总结

    public interface XxxService { // a -> b void a(); void b(); } @Slf4j public class XxxServiceImpl ...

  5. Spring|SpringMVC中的注解

    文章目录 一.Spring注解 @Controller @ResuController @Service @Autowired @RequestMapping @RequestParam @Model ...

  6. Spring和SpringMVC的常用注解

    Spring的部分: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). <context:component-scan base-package=" ...

  7. 【Spring】SpringMVC之基于注解的实现SpringMVC+MySQL

    目录结构: contents structure [-] SprinigMVC是什么 SpringMVC工作原理 @Controller和@RequestMapping注解 @Controller注解 ...

  8. 注解和注释以及Spring和SpringMVC常用的注解

    1.两者区别 注解 :参与代码编译,以@开头的.它是给应用程序看的,单独使用注解毫无意义,一定要跟工具一起使用,这个所谓的工具实际就是能读懂注解的应用程序 注释 :对代码没有影响.对代码起到解释.说明 ...

  9. 【Spring】SpringMVC中浅析Date类型数据的传递

    在控制器中加入如下代码: @InitBinder public void initBinder(ServletRequestDataBinder bin){ SimpleDateFormat sdf ...

随机推荐

  1. js-数字渐增到指定的数字,在指定的时间内完成(有动画效果哦)插件jquery.animateNumber.js

    本来在项目中我自己实现的效果是数字由0渐增到指定的数字就好. 但是,最终效果不理想! Why? 最终指定的数字太大了,TMMD,滚动好久就不到,那用户想看自己有多少钱了,那不是就一直等着!!!所以这个 ...

  2. 微信小程序 之wx.getLocation()获取地理信息中的小坑

    提到wx.getLocation()这个方法,大家都知道是获取地理信息的 今天用这个方法获取定位经纬度后传给后台取得附近markers标记集合, 在开发工具上都正常有标记出现 ,但是在手机测试时,死活 ...

  3. C++对象

  4. 泛域名Wildcard Domain

    泛域名Wildcard Domain 泛域名Wildcard Domain是一种特殊的域名形式.它使用星号作为域名的一级.例如,*.baidu.com就是使用星号作为域名的二级部分.在域名解析中,一个 ...

  5. 转载:P2P技术原理及应用(2)

    转载allen303allen的空间 在Gnutella网络中存在以下问题: 冗余消息多,对带宽的消耗存在一定的浪费.Gnutella网络协议采用泛洪式(Flooding)消息传播机制,这种消息传播机 ...

  6. Ant -----ant标签和自定义任务

    随便记一下 Ant的用法吧.ant ,maven, gradle ,三个打包工具到齐了,Ant 常见标签解析,ant 自定义task . <?xml version="1.0" ...

  7. BZOJ 3065 带插入区间第K小值

    题目描述 Description 从前有n只跳蚤排成一行做早操,每只跳蚤都有自己的一个弹跳力a[i].跳蚤国王看着这些跳蚤国欣欣向荣的情景,感到非常高兴.这时跳蚤国王决定理性愉悦一下,查询区间k小值. ...

  8. AnsiString类型定义的时候可以直接指定代码页,比如950繁体字,936日文

    procedure TForm3.FormCreate(Sender: TObject); type AnsiStringForPage = type AnsiString(950);//代码页 va ...

  9. 常见编码bug

    1.result.replace("abc","bcd");错误 改成result= result.relace("abc","b ...

  10. fastscript增加三方控件

    fastscript增加三方控件 A.关于如何使用第三方控件,增加方法.属性.事件)举例如下: 如:有一控件为edtbutton:TedtButton,我们需要在动态脚本中使用该控件.我们采用如下方法 ...