------- android培训、java培训、期待与您交流! ----------
使用注解启动Spring需要在Spring配置中进行配置
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation中加入http://www.springframework.org/schema/context和http://www.springframework.org/schema/context/spring-context-3.0.xsd
在下面扫描类包
<context:component-scan base-package="包名">
若不想扫描所有的可以再后面加
resource-pattern=""如anno/*.class即只扫描anno子包中的类
也可用
<context:include-filter type="regex" expression="Xxxxxxxx"> 表示要包含的目标类
<context:exclude-filter type="aspectj" expression="Xxxxxxxx"> 表示要排除的目标类
类别 | 示例 | 说明 |
annotation | com.baobaotao.XxxAnnotation | 所有标注了XxxAnnotation的类。采用目标类是否标注了某个注解进行过滤 |
assignable | com.baobaotao.XxxService | 所有继承或扩展XxxService的类。采用目标类是否继承或扩展某个特定类进行过滤 |
aspectj | com.baobaotao..* Service+ | 所有类名以Service结束的类及继承或扩展它们的类。采用AspectJ表达式进行过滤 |
regex | com\.baobaotao\.anno\..* | 所有com.baobaotao.anno类包下的类。采用正则表达式根据目标类的类名进行过滤 |
custom | com.baobaotaoXxxTypeFilter | 采用XxxTypeFile通过代码的方式根据过滤规则。该类必须实现org.springframework.core.type.TypeFilter |