我正在使用 spring-boot,并且希望根据传递的配置文件有条件地加载两个 bean。
@Configuration
@Profile("secure")
public class Secured ... //this should only load when "secure" is supplied
@Configuration
public class NotSecured ... //this should be the default
所以基本上:
如果用户传递了--spring.profiles.active=secured
,我希望加载Secured bean,但不加载NotSecured bean。默认情况下,它应该只加载 NotSecured bean。
这可能吗?
最佳答案
您可以使用“!” not 运算符,即使用 @Profile("!secure")
注释 Bean/Configuration 类,并且仅当“secure”配置文件未激活时才会使用它。
关于spring - 互斥的 bean 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29112334/