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不可以标注在构造器上
推荐使用构造器注入