@Conditional 相关注解, 用在类上表示实例化此类,用在方法上表示执行此方法
- @ConditionalOnProperty
此注解表示:当属性值(application.yml)为某个状态时, 执行: 用在类上表示实例化此类,用在方法上表示执行此方法.
prefix 属性前缀
name 属性key
havingValue 属性value
matchIfMissing true:表示没有此属性则,实例化bean, false:相反.
- @ConditionalOnMissingBean(name="jwtTokenEnhancer")
当不存在id为jwtTokenEnhancer的bean时, 执行方法.
3.@ConfigurationProperties(prefix = "cms")
通常放在类上, 表示此类是配置类, 属性和配置文件(application.yml)属性一一对应. 通常和@EnableConfigurationProperties,@Configuration 联合使用.
@Configuration
@EnableConfigurationProperties(CmsProperties.class)
@ConfigurationProperties(prefix = "cms")
public class CmsProperties {
private BrowserProperties browser = new BrowserProperties();
}

网友评论