在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注入的什么地方。
更多信息请查看 java进阶网 http://www.javady.com
分享到:
相关推荐
此工具自动生成非注解时Spring整合MyBatis时需要的一些配置文件,对于使用较新版本的spring,可以忽视生成的dao的配置文件,建议采用spring的扫描方式。生成的GeneratorConfigXML修改jdbc驱动位置后可直接用使用...
使用Spring的注解方式实现AOP的细节
使用Spring配置文件实现AOP
Spring demo 自动检测注解
Spring java注解,元注解和自定义注解 Spring java注解,元注解和自定义注解 Spring java注解,元注解和自定义注解 Spring java注解,元注解和自定义注解 Spring java注解,元注解和自定义注解
公司的java项目中spring使用注解依赖jar
在非spring注解类中使用spring容器中的bean_普通类中使用yml配置文件中的配置信息,在大数据采集项目中用到的,已经测试过了
Spring注解配置中间层供Struts2使用 1.spring通过注解方式生成中间层 2.不使用Struts2的常量struts.objectFactory也可识别中间层
spring注入文件写法(包括hibernate注入、dao注入等等)
Spring框架xml注解配置方式实例,包括Maven配置文件pom.xml、Springxml配置文件ApplicationContext-1.xml,以及类源码
spring3 注解 详解spring3 注解 详解spring3 注解 详解
spring+springMVC+BlazeDS注解方式的配置文件.
spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件...
Spring开发的依赖包和配置文件,只有引用就行
Spring通过注解实现IOC,Spring通过注解实现IOC,Spring通过注解实现IOC
strut2 spring hibernate web 相关配置文件strut2 spring hibernate web 相关配置文件strut2 spring hibernate web 相关配置文件strut2 spring hibernate web 相关配置文件strut2 spring hibernate web 相关配置文件
spring配置文件实例
最近使用了springAOP编程,文档里面包含了springAOP的代码示例及详细注释说明,使用的是注解配置模式
Quartz2.2.1基于Spring注解方式配置QuartzL,具体过程的效果看博文 http://blog.csdn.net/evankaka/article/details/45400781
spring3注解详细