Spring
这个注解表明该类会作为组件类,并告知Spring要为该类创建bean。
@Component
给组件类起别名,默认是类的首字母小写
@Component("abc")
组件扫描,默认会扫描与配置类相同的包及子包,也可以指定要扫描的路径
使用String类型表示的基础包是 **类型不安全的(not type-safe)**如果你重构代码的话,你所使用的基础包可能会出现错误。
我们可以将其指定为包中的类或接口,这些类所在的包将会作为组件扫描的基础包
@ComponentSacn
@ComponentSacn("com.yjyq61")
@ComponentScan(basePackages = "yjyq61");
@ComponentScan(basePackages = {"yjyq61","yjyq62"});
@ComponentScan(basePackageClasses = {yjyq61.class,yjyq62.class})
加载配置类
@ContextConfiguration
@ContextConfiguration(classes=Config.class)
JAVA依赖注入规范中的@Named注解来为bean设置ID
Spring支持@Named作为@Component的代替方案,两者之间有一些细微的差异,但是在大多数场景中,他们是可以互相替换的
@Named("test")
@PostConstruct修饰的方法会在spring注入完成后执行
@PostConstruct
@PreConstruct修饰的方法会在destroy()方法之后运行,在Servlet被彻底卸载之前。
@PreConstruct说明
RabbitMQ
监听并发布队列
@RabbitListener(queuesToDeclare = @org.springframework.amqp.rabbit.annotation.Queue("queueName"))
@RabbitListener(queuesToDeclare = @Queue("queueName"))
TK.Mapper
忽略实体字段
@Transient
private String some
返回主键
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id;
下面3个都是用来注入的注解
@Resources //java
@Inject //java
@Autowired //Spring
@Resources 优先级:Match by Name > Match by Type >Match by Qualifier
@Inject 优先级:Match by Type > Match by Qualifier > Match by Name
@Autowired 和 @inject 一样,只是是Spring的注解