Stereotype注解是各种元注解的组合
例如
可以自己自定义注解
package cn.tedu.ann;
import org.springframework.stereotype.Component;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Component
public @interface MyService {
}
package cn.tedu.add;
import cn.tedu.ann.MyService;
@MyService
public class MyDemoService {
}
@Autowired可以用在属性、方法、构造器上 而 @Resource不可以标注在构造器上
推荐使用构造器注入
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/weixin_55740233/article/details/120794414
内容来源于网络,如有侵权,请联系作者删除!