@Configuration 启动时将该类生成bean交给Spring管理
@Bean 从方法中返回一个bean交给Spring管理,默认用方法名作为beanName,可指定name(推荐)
@Primary 存在多个bean时首选你了
@Qualifier 通过name得到一个bean,和@Autowired结合使用
@PostConstruct 我来自java,我先跑,我只跑一次
@Async 想让我干活,再给我一个线程,你可以不管我
@Controller @Service @Repositry @Mapper 分层开发web服务的几个常客
@Aspect 告诉我想额外的干些啥,我暗地里帮你搞定
根据条件注入Bean
@ConditionalOnBean 当容器有指定Bean的条件下注入
@ConditionalOnMissingBean 当容器没有指定Bean的情况下才注入
@ConditionalOnClass 当容器有指定类的条件下
@ConditionalOnMissingClass 当容器没有指定类的情况下
@ConditionalOnProperty 指定的属性是否有指定的值,如
@ConditionalOnProperty(
name = {"spring.kafka.jaas.enabled"}
)
@ConditionalOnSingleCandidate 当前指定Bean在容器中只有一个,或者虽然有多个但是指定首选Bean
@ConditionalOnExpression 基于SpEL表达式作为判断条件 @ConditionalOnExpression("'true'.equals('${redis.enable}')")