class MyCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata arg1) {
String property = context.getEnvironment().getProperty("spring.profiles.active");
if (property != null && property.contains("https")) {
return true;
}
return false;
}
}
@Bean
@Conditional(MyCondition.class)
...
本文介绍了一种基于Spring框架的条件Bean加载方法,通过实现Condition接口并覆盖matches方法,根据spring.profiles.active属性判断是否包含https来决定特定Bean的加载。此方法为动态配置提供了灵活性。
2万+

被折叠的 条评论
为什么被折叠?



