注解使用导入依赖

常用注解:



注意,给测试类起名字的时候千万不要定义成Test,测试的方法不可以有参数,不可以有返回值


在使用注解的时候,还需要告诉spring应该从哪个包开始扫描,一般在定义的时候都写上相同包的路径
需要导入context命名空间

当定义好注解的扫描路径之后,可以做更细粒度的控制,可以选择扫描哪个注解,也可以选择不扫描哪个注解
include-filter:表示要包含扫描的注解,一般不会定义此规则,但是如果引入的第三方包中包含注解,此时就需要使用此标签来进行标识。
exclude-filter:表示要排除扫描的注解,使用较多

例:

@Qualifier注解的使用方式:



@Qualifier注解也可以定义在方法的参数列表中,可以指定当前属性的id名称
@Resource注解的使用方式:

@AutoWired注解的使用方式:

使用@Resource可以完成跟@AutoWired相同的功能,但是要注意他们之间的区别:
