<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www./schema/beans" xmlns:xsi="http://www./2001/XMLSchema-instance" xmlns:jee="http://www./schema/jee" xmlns:tx="http://www./schema/tx" xmlns:context="http://www./schema/context" xmlns:aop="http://www./schema/aop" xsi:schemaLocation="http://www./schema/beans http://www./schema/beans/spring-beans-2.5.xsd http://www./schema/context http://www./schema/context/spring-context-2.5.xsd http://www./schema/tx http://www./schema/tx/spring-tx-2.5.xsd http://www./schema/aop http://www./schema/aop/spring-aop-2.5.xsd http://www./schema/jee http://www./schema/jee/spring-jee-2.5.xsd"> <description>Spring配置文件</description> <!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 --> <context:annotation-config /> <context:component-scan base-package="test.haohui"> <!-- <context:exclude-filter type="regex" expression="test\.haohui\.resl\.controller\..*" /> --> <!--exclude-filter 排除在外的 --> <context:include-filter type="regex" expression="test\.haohui\.resl\.controller\..*" /> <!--exclude-filter 包含在内的 --> <context:include-filter type="aspectj" expression="test.haohui.resl.service.*" /> </context:component-scan> </beans> 扫描过滤方式
下面是一个简单的例子:
值得注意的是 <context:component-scan/> 配置项不但启用了对类包进行扫描以实施注释驱动 Bean 定义的功能,同时还启用了注释驱动自动注入的功能(即还隐式地在内部注册了 默认情况下通过 |
|
来自: CevenCheng > 《Spring-3.0》