Spring @Conditional 基于数据库表中的值 [英] Spring @Conditional based on a value in database table
问题描述
条件评估取决于数据库表中提供的值
Condition evaluation depends on a value provided in data base table
@Component
public class XYZCondition implements Condition{
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
//based on value defined in DB should return true/false
}
}
由于条件很早执行,无法获取数据库值有没有其他方法可以实现这一目标?
As Condition is executing very early, unable to fetch db value is there any alternate way to achieve this ?
推荐答案
可以在应用程序工作期间更改数据库值,而重新加载应用程序上下文似乎不是一个好主意.所以我建议使用配置属性来选择哪些 bean 应该在上下文中可用.
Database values can be changed during application work, while it doesn't seem a good idea to reload application context. So I would recommended using configuration properties to choose which beans should be available in context.
此外,还有一个 Spring Cloud Config,允许您将配置存储在 git 或其他一些存储中.一旦配置更改,其使用者可能会重新启动上下文.似乎也值得一看.
Moreover, there's a Spring Cloud Config that allows you to store configuration in git or some other storages. Its consumers may restart context once configuration changes. It seems worth talking a look at it as well.
这篇关于Spring @Conditional 基于数据库表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!