其他分享
首页 > 其他分享> > spring使用注解的好处

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;
}

标签:set,Autowired,spring,autowired,好处,使用,注解,ElementType
来源: https://www.cnblogs.com/ymsblog/p/15745869.html