spring使用注解时配置文件的写法
2012-04-11 12:04
609 查看
在spring的配置文件中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
</beans>
我们会看到这样写:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="cn.test">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
</beans>
<context:component-scan/> 配置项不但启用了对类包进行扫描以实施注释驱动 Bean 定义的功能,同时还启用了注释驱动自动注入的功能(即还隐式地在内部注册了 AutowiredAnnotationBeanPostProcessor 和 CommonAnnotationBeanPostProcessor),因此当使用 <context:component-scan/> 后,就可以将 <context:annotation-config/>
移除了。
<context:component-scan/> 的 base-package 属性指定了需要扫描的类包,类包及其递归子包中所有的类都会被处理。
通过exclude-filter 把所有@Controller注解的控制器组件排除。因为我们知道@Controller一般标注的是action,不用把action注入的什么地方。
参考博文: http://913.iteye.com/blog/1280808
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
</beans>
我们会看到这样写:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="cn.test">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
</beans>
<context:component-scan/> 配置项不但启用了对类包进行扫描以实施注释驱动 Bean 定义的功能,同时还启用了注释驱动自动注入的功能(即还隐式地在内部注册了 AutowiredAnnotationBeanPostProcessor 和 CommonAnnotationBeanPostProcessor),因此当使用 <context:component-scan/> 后,就可以将 <context:annotation-config/>
移除了。
<context:component-scan/> 的 base-package 属性指定了需要扫描的类包,类包及其递归子包中所有的类都会被处理。
通过exclude-filter 把所有@Controller注解的控制器组件排除。因为我们知道@Controller一般标注的是action,不用把action注入的什么地方。
参考博文: http://913.iteye.com/blog/1280808
相关文章推荐
- spring使用注解时配置文件的写法
- spring使用注解时配置文件的写法
- spring使用注解时配置文件的配置
- Hibernate注解配置 在Spring的配置文件里写法
- spring框架,可以没有spring.xml(即配置<beans>的文件吗?即不使用xml方式配置,而是只使用注解的方式配置
- 使用Spring注解获取配置文件信息
- Hibernate注解配置 在Spring的配置文件里写法
- Spring核心框架IOC---- 使用注解完成IOC配置---- 注解配置文件
- Spring整合JUnit4测试,使用注解引入一个或多个配置文件
- 关于使用注解的Spring配置文件的配置<context:annotation-config/>&&<context:component-scan base-package=”XX.XX”/>
- Spring整合JUnit4测试时,使用注解引入多个配置文件
- Spring整合JUnit4测试使用注解引入多个配置文件
- Spring整合JUnit4测试,使用注解引入一个或多个配置文件
- spring boot:使用@ConfigurationProperties注解加载配置文件
- Spring整合JUnit4测试,使用注解引入一个或多个配置文件
- Spring整合JUnit4测试,使用注解引入一个或多个配置文件
- Spring 的配置文件简化与注解的使用
- hibernate3使用注解,spring配置文件applicationContext.xml的配置
- Spring整合JUnit4测试,使用注解引入一个或多个配置文件
- 8 -- 深入使用Spring -- 4...6 AOP代理:基于注解的XML配置文件的管理方式