- 浏览: 182702 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
grzrt:
zkf55915 写道哥们怎么用啊
好久不用了,就是看帮助资 ...
淘宝MetaQ开源消息队列安装 -
zkf55915:
哥们怎么用啊
淘宝MetaQ开源消息队列安装 -
grzrt:
jinnianshilongnian 写道整这个了?
没有 看 ...
linux内核中链表的实现 -
jinnianshilongnian:
整这个了?
linux内核中链表的实现
<context:component-scan base-package="leot.test" use-default-filters="false">
<!-- 扫描符合@Service @Repository的类 -->
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" />
</context:component-scan>
Spring 2.5引入了更多典型化注解(stereotype annotations):
@Component
、@Service
和
@Controller
。
@Component
是所有受Spring管理组件的通用形式;而@Repository
、@Service
和
@Controller
则是@Component
的细化,用来表示更具体的用例(例如,分别对应了持久化层、服务层和表现层)。也就是说,你能用@Component
来注解你的组件类,但如果用@Repository
、@Service
或@Controller
来注解它们,你的类也许能更好地被工具处理,或与切面进行关联。例如,这些典型化注解可以成为理想的切入点目标。当然,在Spring
Framework以后的版本中, @Repository
、@Service
和
@Controller
也许还能携带更多语义。如此一来,如果你正在考虑服务层中是该用
@Component
还是@Service
,那@Service
显然是更好的选择。同样的,就像前面说的那样,
@Repository
已经能在持久化层中进行异常转换时被作为标记使用了。”
下面是网上目前关于组件扫描最详细的介绍
Spring applicationContext.xml的<context:component-scan>標籤用途比我想像的還要實用。而且後來才 知道,有了<context:component-scan>,另一個<context:annotation- config/>標籤根本可以移除掉,因為被包含進去了。原本我survery Spring3通常只配置成<context:component-scan base-package="com.foo.bar"/>,意即在base-package下尋找有@Component和 @Configuration的target Class。而現在如下的飯粒:
<context:component-scan
base-package="com.foo" use-default-filters
="false"> |
<context:component-scan>提供兩個子標籤:<context:include-filter> 和<context:exclude-filter>各代表引入和排除的過濾。而上例把use-default-filters屬性設為 false,意即在base-package所有被宣告為@Component和@Configuration等target Class不予註冊為bean,由filter子標籤代勞。
filter標籤在Spring3有五個type,如下:
Filter Type | Examples Expression | Description |
annotation | org.example.SomeAnnotation | 符合SomeAnnoation的target class |
assignable | org.example.SomeClass | 指定class或interface的全名 |
aspectj | org.example..*Service+ | AspectJ語法 |
regex | org\.example\.Default.* | Regelar Expression |
custom | org.example.MyTypeFilter | Spring3新增自訂Type,實作org.springframework.core.type.TypeFilter |
所以上例用的regex就有個語病,com.foo.config.* 可以找到com.foo.config.WebLogger,但也可以找到com1fool2config3abcde,因為小數點在Regex是任意字 元,是故要用\.把小數點跳脫為佳。(2010/3/15補充:但要使用\.方式,其use-default-filters不能為false,否則抓不 到,感覺是Bug)
Spring3提供豐富的Filter支援,有益配置策略,不需面臨Configuration Hell,比如Regex的com\.foo\.*\.action\.*Config,這樣就可以找到com.foo package下所有action子package的*Config的target class。
我按他的例子,配置了我自己的如下:
<context:include-filter type="regex" expression="com.lee.finance.budget.service.*"/>
<context:include-filter type="regex" expression="com.lee.finance.budget.security.*"/>
</context:component-scan>
<context:include-filter type="regex" expression="com.lee.finance.budget.*"/>
</context:component-scan>
<context:include-filter type="regex" expression="com\.lee\.finance\.budget\.service.*"/>
</context:component-scan>问题依旧
<context:include-filter type="regex" expression="com.lee.finance.budget.service.TestService"/>
</context:component-scan>
<context:include-filter type="regex" expression=".service.*"/>
</context:component-scan>
发表评论
-
项目代码质量控制
2014-10-20 17:15 782在以后的开发项目时可以适当使用工具进行程序检查: 1、F ... -
WorkbookFactory 找不到
2013-11-08 10:46 920在最近的POI版本中,poi-3.9.jar包中找不到Work ... -
记一次JVM GC日志分析
2013-03-08 21:36 1710这几天在准备升级JDK版本到1.6,对目前线上JVM(版 ... -
Eclipse 相同变量的高亮 及颜色
2013-02-18 17:26 1583在Eclipse/MyEclipse中如果不小心把变量的高 ... -
java jstack dump 线程 介绍 解释
2013-02-05 15:52 1170hi,all: 最近抽时间把JVM运行 ... -
[转载]JDMK 基本JMX配置( html adaptor)
2013-01-07 13:37 1653原文地址: JDMK 基本JMX配置( html adap ... -
JAVA中的继承分析
2012-12-27 11:43 5079为什么写这篇博客,之前对继承的理解知识大体理论上,最近 ... -
JVM学习之:虚拟机中的运行时栈帧总结(二)
2012-12-12 19:46 796在 JVM学习之:虚拟机 ... -
JVM学习之:虚拟机中的运行时栈帧总结(一)
2012-12-12 19:45 818每 个人都知道,各种各样的动画视频,都是由一帧一帧图片连 ... -
JAVA字符串占位符
2012-12-06 08:24 3177包 java.text.MessageFormat java ... -
copy项目是容易出现的错误--webAppRootKey错误
2012-12-05 21:18 687Tomcat 发布多个项目时抛的webAppRootKey错误 ... -
web.xml配置总结
2012-12-05 20:50 628一、关于webAppRootKey的定义 默 ... -
spring组件扫描<context:component-scan/>使用详解
2012-12-05 19:14 697关于spring自动检测组件的使用方式网上太多了,而且也不 ... -
static class 静态类(Java)
2012-11-23 20:20 816一般情况下是不可以用static 修饰类的。 ... -
java jvm 调优实战
2012-11-13 10:01 7701.eclipse 打印gc日志 eclipse根目录 ... -
Zookeeper的一致性协议:Zab
2012-11-04 16:14 1165Zookeeper使用了一种称为 ... -
浅谈java内存模型
2012-10-30 19:29 757不同的平台,内存模 ... -
JVM分代垃圾回收策略的基础概念
2012-08-15 12:43 662由于不同对象的生命周期不一样,因此在JVM的垃圾回收策略中有分 ... -
bloom filter 的Java 版
2012-07-26 21:50 847属于转贴:http://www.cnblo ... -
JAVA 条件表达式 陷阱
2012-07-25 18:34 1236代码: Map<String, Integer& ...
相关推荐
NULL 博文链接:https://gaozzsoft.iteye.com/blog/1523898
<artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>...
赠送jar包:spring-context-support-1.0.10.jar; 赠送原API文档:spring-context-support-1.0.10-javadoc.jar; 赠送源代码:spring-context-support-1.0.10-sources.jar; 赠送Maven依赖信息文件:spring-context-...
主要介绍了Spring 报错:元素 "context:component-scan" 的前缀 "context" 未绑定的问题解决的相关资料,需要的朋友可以参考下
<context:component-scan base-package="com.baobaotao.web"/> <!-- ②:启动Spring MVC的注解功能,完成请求和注解POJO的映射 --> <bean class="org.springframework.web.servlet.mvc.annotation. ...
<groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>RELEASE</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> ...
spring使用logback的扩展,使用起来非常方便。在web.xml中配置: <context-param> <param-name>logbackConfigLocation</param-name> <param-value>/WEB-INF/conf/logback.xml</param-value> </context-param> ...
<context:component-scan base-package="Controller" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/" /> ...
开发Spring的过程中出现Eclipse不能识别<tx:advice />标签,需要引用 spring-tx标签,spring-tx-4.0.xsd 可以解决标签不识别的问题
<context:component-scan base-package="com.ccc"/> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:order="0" /> <!-- 配置事务管理器 針對MES數據庫-...
<context:component-scan base-package="Mode"></context:component-scan> //表示在包mode下面的类将扫描带有@Component,@Controller,@Service,@Repository标识符的类并为之注入对象。 据说是因为XML配置太烦锁而...
<param-value>classpath:spring/app.xml,classpath:org/codehaus/xfire/spring/xfire.xml</param-value> </context-param> <!--配置xfire ws--> <servlet> <servlet-name>XFireServlet</servlet-name> ...
<context:component-scan base-package="com.org"/> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org....
<context:component-scan base-package="*" /> <!-- <aop:config>--> <!-- execution第一个星号代表任何返回类型,第二个星号代表com.sbz.service下的所有包,第三个星号代表所有方法,括号中的两个点代表任何...
<context:component-scan base-package="com.mvc" /> <mvc:annotation-driven /> <mvc:resources mapping="/resources/**" location="/resources/" /> <mvc:default-servlet-handler /> <aop:config proxy-...
<context:component-scan base-package="org.whvcse"></context:component-scan> <tx:annotation-driven transaction-manager="txManager" /> <!-- <aop:config> <aop:pointcut id="defaultServiceOperation" ...
<context:component-scan base-package="com.bbs"/> <!--注解支持--> <mvc:annotation-driven/> <!--视图解析--> <bean id="viewResolver" class="org.springframework.web.servlet.view....
在web.Xml中<context-param> <param-name>contextConfigLocation</param-name> ... <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>
<context:component-scan base-package="com.itheima.service"/> <!--aop面向切面编程,切面就是切入点和通知的组合--> <!--配置事务管理器--> <bean id="transactionManager" class="org.springframework.jdbc...