Spring Profiles
- 환경에 맞게 설정을 가져오기
- 여러가지 방식으로 설정
- Bean @Profile
- jvm properties
- web.xml
- Environment
@ActiveProfiles
Sample
@Component
@Profile("dev")
public class DevDatasourceConfig
@Component
@Profile("!dev")
public class DevDatasourceConfig
<beans profile="dev">
<bean id="devDatasourceConfig"
class="com.okdevtv.profiles.DevDatasourceConfig" />
</beans>
WebApplicationInitializer
@Configuration
public class MyWebApplicationInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.setInitParameter("spring.profiles.active", "dev");
}
}
@Autowired
private ConfigurableEnvironment env;
// ...
env.setActiveProfiles("someProfile");
-Dspring.profiles.active=dev
export spring_profiles_active=dev
@ActiveProfiles("dev")
related
ref