spring使用注解的好处

使用注解的步骤.

1.导入配置

第二步:开启注解扫描
context:annotation-config/

Autowired注解的使用

1.可以直接在属性上使用,也可以在set方法上使用
2.使用autowired我们可以不需要写set方法,前提是这个自动装配在ioc中,是根据
ByName去查询的

科普

@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Autowired {
boolean required() default true;
}

posted @ 2021-12-29 17:27  এএ᭄念卿এএ᭄  阅读(26)  评论(0编辑  收藏  举报