프로필을 사용할 수 있습니다.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd" >
<!-- here goes common beans -->
<beans profile="Prof_1">
<import resource="./first-config.xml" />
</beans>
<beans profile="Prof_2">
<import resource="./second-config.xml" />
</beans>
</beans>
동시에 여러 프로필을 활성화하거나 활성화하지 않을 수도 있습니다. programtaically 우리의 web.xml에 초기화를 추가 할 필요가이 작업을 수행 할 수 있지만 여러 가지 방법이 있습니다 활성화하려면
<context-param>
<param-name>contextInitializerClasses</param-name>
<param-value>com.test.MyCustomInitializer</param-value>
</context-param>
MyCustomInitializer는
public class MyCustomInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
try {
String activeProf;
// some logic to either read file/env variable/setting to determine which profile to activate
applicationContext.getEnvironment().setActiveProfiles(activeProf);
} catch (IOException e) {
e.printStackTrace();
}
}
}
당신이 실제 사용 사례에 대한 자세한 정보를 제공 할 수 있습니다 다음과 같습니다? –
질문이 있은 지 오래되었지만 아직 답변을 찾지 못했다면 Sprint Profile 기능이 그러한 작업을위한 도구 일 수 있습니다. –
스프링 자바 설정과'@ Conditional' 어노테이션으로 매우 간단하게 처리 할 수 있습니다. 그러나 xml 구성이 중요하다면 다음 기사를 살펴보십시오. http://robertmaldon.blogspot.ru/2007/04/conditionally-defining-spring-beans.html – androberz