context:exclude-filter 与 context:include-filter 转

1 在主容器中(applicationContext.xml),将Controller的注解打消掉

  1. <context:component-scan base-package="com">
  2. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  3. </context:component-scan>

2 而在springMVC配置文件中将Service注解给去掉 

  1. <context:component-scan base-package="com">
  2. <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  3. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
  4. </context:component-scan>

因为spring的context是父子容器,所以会产生冲突,Controller会进步前辈行扫描装配,而此时的
Service还没有进行事务的加强处理惩罚,获得的将是原样的Service(没有经过事务加强处理惩罚,故而没有事务处理惩罚才能)
,最后才是applicationContext.xml中的扫描设备进行事务处理惩罚

上面的好像有错

Spring注解自动注入Bean

我们知道采用Spring注解时,配置如下:

  1. <context:annotation-config />
  2. <context:component-scan base-package="cn.itkt"></context:component-scan>

这样的话,在com包及其所有子包下的所有类如果含有@Component、@Controller、@Service、@Repository等 注解的话都会自动纳入到Spring容器中,但是每个类都一个个加上注解,有时难免觉得繁琐,其实Spring也为我们提供了自动为类加上注解的功能。配 置如下:

  1. <context:component-scan base-package="cn.itkt" use-default-filters="false">
  2. <context:include-filter type="regex" expression="cn.itkt.*.service.*.*" />
  3. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  4. </context:component-scan>

我们可以看到加了context:include-filter标签和context:exclude-filter标签。

context:include-filter

此标签的含义是:在其扫描到的所有类中,全部自动加上注解并纳入Spring容器中,比如有个类为

  1. public class StudentService implements IStudentService {
  2. }

那么该标签等用于为StudentService类加上@Component注解,且bean的id为studentService。

  1. @Component("studentService")
  2. public class StudentService implements IStudentService {
  3. }

context:exclude-filter

此标签的含义是:排除扫描到的所有类,不纳入Spring容器中。

但需要注意的是,采用自动注入,类名不能相同(即便包名不同),因为自动注入时,id与类名相同,所以如果两个类名一样的话,会因为Bean的id相同而报错。

如果类名一定要相同的话,只能是其中一个类,手动加上注解并将名称改为其他。

context:exclude-filter 与 context:include-filter 转的更多相关文章

  1. Web.xml详解(转)(Filter,context,listener)

    web.xml 详细解释!!(链接) web.xml加载过程(步骤) 首先简单说一下,web.xml的加载过程. 当我们去启动一个WEB项目时,容器包括(JBoss.Tomcat等)首先会读取项目we ...

  2. dedecms /include/filter.inc.php Local Variable Overriding

    catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 filter.inc.php这个文件在系统配置文件之后,里面有forea ...

  3. 织梦Dedecms系统可疑文件include/filter.inc.php扫描出漏洞,该如何解决?

    今天在做网站监察的时候,发现网站出了一个问题,在对网站做木马监测的时候,扫描出一个可疑文件:/include/filter.inc.php,建议删除,但仔细检查后,发现此文件是织梦(Dedecms)系 ...

  4. Spring Security 入门(1-6-2)Spring Security - 内置的filter顺序、自定义filter、http元素和对应的filterChain

    Spring Security 的底层是通过一系列的 Filter 来管理的,每个 Filter 都有其自身的功能,而且各个 Filter 在功能上还有关联关系,所以它们的顺序也是非常重要的. 1.S ...

  5. context:component-scan" 的前缀 "context" 未绑定。

    SpElUtilTest.testSpELLiteralExpressiontestSpELLiteralExpression(cn.zr.spring.spel.SpElUtilTest)org.s ...

  6. Android中,Context,什么是Context?

    注:本文翻译自Context, What Context?,原文链接在这里,作者是Dave Smith.ps:译者链接http://blog.csdn.net/race604/article/deta ...

  7. Android开发之Android Context,上下文(Activity Context, Application Context)

    转载:http://blog.csdn.net/lmj623565791/article/details/40481055 1.Context概念Context,相信不管是第一天开发Android,还 ...

  8. System.Drawing.Design.UITypeEditor自定义控件属性GetEditStyle(ITypeDescriptorContext context),EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...

  9. Spring context:component-scan中使用context:include-filter和context:exclude-filter

    Spring context:component-scan中使用context:include-filter和context:exclude-filter XML: <?xml version= ...

  10. DirectX:在graph自己主动连线中增加自己定义filter(graph中遍历filter)

    为客户提供的视频播放的filter的測试程序中,採用正向手动连接的方式(http://blog.csdn.net/mao0514/article/details/40535791).因为不同的视频压缩 ...

随机推荐

  1. Fix "Missing Scripts"

    一.Missing Scripts(脚本引用丢失) 请看下面的两张图的Warn(脚本引用丢失),在某些情况下我们会遇到这个警告. 二.解决办法 参考资料 http://unitygems.com/la ...

  2. Unity-WIKI 之 DrawArrow

    组件作用 Unity画方向箭头类库,在Scene视图或在Game视图打开Gizmos查看效果 效果预览   wiki地址 http://wiki.unity3d.com/index.php/DrawA ...

  3. Linux平台Java调用so库-JNI使用例子

    1.确保gcc编译器已安装 2.编写HelloJNI.java代码,用native声明需要用C实现的函数.如果源程序是包含在package里的话,应该建立同样的文件夹结构,比如/home/swan/t ...

  4. iOS中使用RSA对数据进行加密解密

    RSA算法是一种非对称加密算法,常被用于加密数据传输.如果配合上数字摘要算法, 也可以用于文件签名. 本文将讨论如何在iOS中使用RSA传输加密数据. 本文环境 mac os openssl-1.0. ...

  5. Android开发EditText属性

    Android开发EditText属性 EditText继承关系:View-->TextView-->EditText EditText的属性很多,这里介绍几个:android:hint= ...

  6. sql语句原则

    整理尘封的文档,sql语句方面的几条原则再次回顾一下.更详细版本 1. 尽量使用临时表扫描替代全表扫描: 2. 抛弃in和not in语句,使用exists和not exists替代:IN和EXIST ...

  7. Maven 的 HelloWorld

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  8. [转]hive实例讲解实现in和not in子句

    FROM : http://www.cnblogs.com/ggjucheng/archive/2013/01/03/2842855.html 目前hive不支持 in或not in 中包含查询子句的 ...

  9. MySQL基础 - 外键和约束

    在工作中经常会遇到不少不同的观点,比如对于数据库来说那就是是否要设置外键,设置外键的理由自然不必多说,而不设置外键的理由多半为设置外键影响性能,但就目前工作来讲,还没有涉及到因为外键而引发的数据库瓶颈 ...

  10. 20135220谈愈敏Blog8_进程的切换和系统的一般执行过程

    进程的切换和系统的一般执行过程 谈愈敏 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.com/course/USTC-100002 ...