我在Spring, Java, Ant
网络应用程序中工作。我正在使用 Spring 分析来加载基于环境的属性。下面是示例
@Profile("dev")
@Component
@PropertySource("classpath:dev.properties")
public class DevPropertiesConfig{
}
@Profile("qa")
@Component
@PropertySource("classpath:qa.properties")
public class TestPropertiesConfig {
}
@Profile("live")
@Component
@PropertySource("classpath:live.properties")
public class LivePropertiesConfig{
}
在web.xml中,我们可以给出配置文件
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</context-param>
现在,我的查询是针对我需要创建一个单独的 Java 类的每个环境。
问题:是否可以只有一个类,例如提供配置文件名称作为某些绑定参数,例如@Profile({profile})
.
另外,让我知道是否有其他更好的选择可以实现相同的目标。