Spring Stereotype注解

x33g5p2x  于2021-10-16 转载在 Spring  
字(0.5k)|赞(0)|评价(0)|浏览(363)

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不可以标注在构造器上

推荐使用构造器注入

相关文章

微信公众号

最新文章

更多