【发布时间】:2014-11-28 09:59:51
【问题描述】:
我想为整个包设置配置文件名称,但我不知道如何操作。如果 where 不是简单的方法,那么我必须用 @Profile 注释标记包和子包中的每个类。
<context:component-scan/> 标签不支持profile 这样的属性,所以我不知道。
【问题讨论】:
标签: java spring spring-profiles
我想为整个包设置配置文件名称,但我不知道如何操作。如果 where 不是简单的方法,那么我必须用 @Profile 注释标记包和子包中的每个类。
<context:component-scan/> 标签不支持profile 这样的属性,所以我不知道。
【问题讨论】:
标签: java spring spring-profiles
如果您不混合使用 XML 和 Java 配置,您可以在目标包中有 @ComponentScan 注释的 bean 上使用 @Profile 吗?
与 XML 类似:您可以有两个不同的 <beans ...> 部分,每个部分具有不同的配置文件,并且在每个部分中您定义自己的 <context:component-scan basePackage="..." />
@Configuration
@Profile("profile1")
@ComponentScan(basePackage="package1")
class Config1 {
}
@Configuration
@Profile("profile2")
@ComponentScan(basePackage="package2")
class Config2 {
}
【讨论】: