在@Profile中使用通配符

ric*_*oon 6 java spring spring-boot

如何在中使用通配符@Profile

例如:

@Profile("*-from-db")
private class Foo {
Run Code Online (Sandbox Code Playgroud)

Foospring.profiles.active以结尾的Bean应该被激活"-from-db";如dev-from-db,qa-from-db,prod-from-db等。

Kam*_*mil 1

仅使用 @Profile 注释是无法做到这一点的。您可以尝试使用条件匹配器。请查看这篇文章我可以不(!)收集弹簧配置文件吗?这是一个https://raymondhlee.wordpress.com/2015/05/31/using-spring-4-condition-to-control-bean-registration/。它应该引导您走向正确的方向。