@Component大致可以分为以下几个注解:
a.@controller控制器(注入服务),用于标注控制层组件(如struts中的action)
b.@service服务(注入dao),用于标注业务层组件
c.@repository dao(实现dao访问),用于标注数据访问组件,即DAO组件
一般版本低的JDK在用到@Resource注解时,可能需要引入j2ee/common-annotations.jar。JDK1.6或以上,不需要引入。
下面这个XML代码段是引入component的扫描组件(想要实现组件方式扫描,必须在XML中配置下面代码,其中base-package为需要扫描的包(含所有子包)):
<!--扫描Web类包 启动时先于applicationContext加载--> <context:component-scan base-package="com.hide168"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> </context:component-scan>