| 카테고리1 | 프로그래밍 |
|---|---|
| 카테고리2 | 자바 |
| 제목 | 개발용 properties 파일 설정하기 |
| 작성자 | 고성훈 |
| 작성일 | 2024-12-23 11:37:03 |
| 프로젝트를 한번 실행한 후 바로 종료하고
프로젝트 우클릭 > Run As > Run Configurations > Arguments > VM arguments 에 -Dspring.profiles.active=dev 넣기 [적용 설정] @Configuration public class DataSourceConfig { @Autowired private Environment env; @PostConstruct public void init() throws Exception { // Run Configurations > Arguments > VM arguments 에 -Dspring.profiles.active=dev 을 입력하여 개발용 properties 적용하기 String activeProfile = System.getProperty("spring.profiles.active", ""); MutablePropertySources propertySources = ((ConfigurableEnvironment) env).getPropertySources(); if (activeProfile.isEmpty()) { propertySources.addLast( new ResourcePropertySource("classpath:egovframework/egovProps/config.properties")); } else { propertySources.addLast( new ResourcePropertySource("classpath:egovframework/egovProps/config" + activeProfile + ".properties")); } } } | |