Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只想在配置了@ServiceMongo 的情况下自动配置 a 。
@Service
合适的方法是什么?
我的想法是使用:
@ConditionalOnBean(MongoTemplate.class)
@Conditional我应该使用更好的方法吗?
@Conditional
是的,您可以对具有特定价值的属性使用条件。这是简单的注释:
@ConditionalOnProperty(value = "database.type", havingValue = "MONGO", matchIfMissing = true)
例如,您可以将注释用于与指定数据库相关的所有 bean,或者创建以属性为条件的配置