context:exclude-filter 与 context:include-filter 转
context:exclude-filter 与 context:include-filter 转
1 在主容器中(applicationContext.xml),将Controller的注解打消掉
- <context:component-scan base-package="com">
- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
- </context:component-scan>
2 而在springMVC配置文件中将Service注解给去掉
- <context:component-scan base-package="com">
- <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
- </context:component-scan>
因为spring的context是父子容器,所以会产生冲突,Controller会进步前辈行扫描装配,而此时的
Service还没有进行事务的加强处理惩罚,获得的将是原样的Service(没有经过事务加强处理惩罚,故而没有事务处理惩罚才能)
,最后才是applicationContext.xml中的扫描设备进行事务处理惩罚
上面的好像有错
Spring注解自动注入Bean
我们知道采用Spring注解时,配置如下:
- <context:annotation-config />
- <context:component-scan base-package="cn.itkt"></context:component-scan>
这样的话,在com包及其所有子包下的所有类如果含有@Component、@Controller、@Service、@Repository等 注解的话都会自动纳入到Spring容器中,但是每个类都一个个加上注解,有时难免觉得繁琐,其实Spring也为我们提供了自动为类加上注解的功能。配 置如下:
- <context:component-scan base-package="cn.itkt" use-default-filters="false">
- <context:include-filter type="regex" expression="cn.itkt.*.service.*.*" />
- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
- </context:component-scan>
我们可以看到加了context:include-filter标签和context:exclude-filter标签。
context:include-filter
此标签的含义是:在其扫描到的所有类中,全部自动加上注解并纳入Spring容器中,比如有个类为
- public class StudentService implements IStudentService {
- }
那么该标签等用于为StudentService类加上@Component注解,且bean的id为studentService。
- @Component("studentService")
- public class StudentService implements IStudentService {
- }
context:exclude-filter
此标签的含义是:排除扫描到的所有类,不纳入Spring容器中。
但需要注意的是,采用自动注入,类名不能相同(即便包名不同),因为自动注入时,id与类名相同,所以如果两个类名一样的话,会因为Bean的id相同而报错。
如果类名一定要相同的话,只能是其中一个类,手动加上注解并将名称改为其他。
context:exclude-filter 与 context:include-filter 转的更多相关文章
- Web.xml详解(转)(Filter,context,listener)
web.xml 详细解释!!(链接) web.xml加载过程(步骤) 首先简单说一下,web.xml的加载过程. 当我们去启动一个WEB项目时,容器包括(JBoss.Tomcat等)首先会读取项目we ...
- dedecms /include/filter.inc.php Local Variable Overriding
catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 filter.inc.php这个文件在系统配置文件之后,里面有forea ...
- 织梦Dedecms系统可疑文件include/filter.inc.php扫描出漏洞,该如何解决?
今天在做网站监察的时候,发现网站出了一个问题,在对网站做木马监测的时候,扫描出一个可疑文件:/include/filter.inc.php,建议删除,但仔细检查后,发现此文件是织梦(Dedecms)系 ...
- Spring Security 入门(1-6-2)Spring Security - 内置的filter顺序、自定义filter、http元素和对应的filterChain
Spring Security 的底层是通过一系列的 Filter 来管理的,每个 Filter 都有其自身的功能,而且各个 Filter 在功能上还有关联关系,所以它们的顺序也是非常重要的. 1.S ...
- context:component-scan" 的前缀 "context" 未绑定。
SpElUtilTest.testSpELLiteralExpressiontestSpELLiteralExpression(cn.zr.spring.spel.SpElUtilTest)org.s ...
- Android中,Context,什么是Context?
注:本文翻译自Context, What Context?,原文链接在这里,作者是Dave Smith.ps:译者链接http://blog.csdn.net/race604/article/deta ...
- Android开发之Android Context,上下文(Activity Context, Application Context)
转载:http://blog.csdn.net/lmj623565791/article/details/40481055 1.Context概念Context,相信不管是第一天开发Android,还 ...
- 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 ...
- Spring context:component-scan中使用context:include-filter和context:exclude-filter
Spring context:component-scan中使用context:include-filter和context:exclude-filter XML: <?xml version= ...
- DirectX:在graph自己主动连线中增加自己定义filter(graph中遍历filter)
为客户提供的视频播放的filter的測试程序中,採用正向手动连接的方式(http://blog.csdn.net/mao0514/article/details/40535791).因为不同的视频压缩 ...
随机推荐
- 第51课 C++对象模型分析(下)
1. 单继承对象模型 (1)单一继承 [编程实验]继承对象模型初探 #include <iostream> using namespace std; class Demo { protec ...
- DoTween NGUI bug
多次动画导致UISprite丢失 DOTween动画进行时与UISprite有冲突,DOTween多次重复同一个动画时,UISprite会莫名的丢失 UISprite动画代码 CUIManager.I ...
- 关于第一个Java应用
一.创建Java源文件 Java应用由一个或多个扩展名为".java"的文件构成,这些文件被称为Java源文件,从编译的角度,则被称为编译单元(Compilation Unit). ...
- 【MySQL】Linux MySQL学习记录
1.查看日志存放路径 show variables like 'general_log_file'; 2.查看日志是否开启 show global variables like 'log_bin%'; ...
- [转]服务器自动化操作 RunDeck
From : http://www.oschina.net/p/rundeck/similar_projects?sort=view&lang=25 RunDeck 是用 Java/Grail ...
- C语言中的深拷贝和浅拷贝
//C语言中的深拷贝和浅拷贝 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #inc ...
- 检测到 LoaderLock:DLL"XXXX"正试图在OS加载程序锁内执行
解决方法: ctrl+D+E或alt+ctl+e或使用菜单调试——>异常——>异常窗口——>Managed Debugging Assistants——>去掉LoaderLoc ...
- XML CDATA的作用
操作XML文件时,如果允许用户输入内容,例如∶"< ".">"."/".""等,当生成XML时,会破坏了XM ...
- c语言自加自减三道题
int x , y,z; x = 0; y = z = -1; x += -z ---y; printf("x=%d\n",x) x = 2 为什么? x + = -z - - ...
- matlab 给某一列乘上一个系数
矩阵M是一个 mxn 的矩阵,现在要给M矩阵的第一列都要乘上10,使其第一列扩大10倍,那肿么做呢? 我第一时间用的是: M(:,1) = M(:,1)*10; //错误的 但是这个错了,结果是不对的 ...