我在Spring中有一个bean,我希望只有当2个配置文件都被激活时才启用它。基本上,它应该是这样的:
@Profile({"Tomcat", "Linux"})
public class AppConfigMongodbLinux{...}
@Profile({"Tomcat", "WindowsLocal"})
public class AppConfigMongodbWindowsLocal{...}
当我使用-Dspring.profiles.active=Tomcat,WindowsLocal
时,我希望它只尝试使用AppConfigMongodbWindowsLocal
,但它仍然尝试注册AppConfigMongodbLinux
。
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appConfigMongodbLinux': Injection of autowired dependencies failed
当两个配置文件都处于激活状态时,使bean只能被注册,这是否可能?还是我使用方法有误? :)
谢谢!!
编辑:发布完整堆栈。
实际上出错的是一个属性在属性文件中缺失,但是这个bean会被激活吗?我想了解这一点,以确保我没有激活错误的bean。
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appConfigMongodbLinux': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.Integer mycompany.config.AppConfigMongodbLinux.mongoPort; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'mongo.port' in string value "${mongo.port}"
... 40 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.Integer mycompany.config.AppConfigMongodbLinux.mongoPort; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'mongo.port' in string value "${mongo.port}"
...
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'mongo.port' in string value "${mongo.port}"