스프링부트 spring.profiles.active에 default값 설정하기
@Slf4j
@EnableScheduling
@SpringBootApplication
public class Server {
public static void main(String[] args) {
System.setProperty("spring.profiles.default", "local");
// SpringApplication.run(Server.class, args);
Properties p = System.getProperties();
Enumeration keys = p.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
String value = (String) p.get(key);
System.out.println(key + ": " + value);
}
}
}
결과
java.vm.specification.vendor: Oracle Corporation os.name: Mac OS X sun.jnu.encoding: UTF-8 spring.profiles.default: local java.class.version: 52.0 |
설정을 하고 실행하면 위와 같이 결과가 나오면 된다.
결론
System.setProperty("spring.profiles.default", "local");
main()에 이렇게 쓰면 됨
요즘 MSA(micro service application) 라서 서버를 잘게잘게 쪼개서 만드는데 이거 나름대로 장단점이 있다. 장점이야 잘 알고 있으니까 단점에 대해 이야기를 해보면 app이 여러개라는 것이다.
app이 여러개라서 프로젝트를 여러개 열어놓거나 고칠 일이 많은데 이걸 또 받았다 올렸다 하면 매번 -Dspring.profiles.active=dev 이걸 넣어주는것도 일이다.
그래서 디폴트 값을 넣어주면 로컬에서 개발할때는 -Dspring.profiles.active=local 이걸 안넣어줘도 되게 하기 위해 이 기능이 필요하다.
그러면
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.6.RELEASE)
2018-11-16 13:30:41.773 INFO 12344 --- [ main] com.plutusds.events.server.Server : Starting Server on Plutusdsui-MacBook-Pro-3.local with PID 12344 (/Users/mattheu/git/java/events-server/target/classes started by mattheu in /Users/mattheu/git/java/events-server)
2018-11-16 13:30:41.776 INFO 12344 --- [ main] com.plutusds.events.server.Server : No active profile set, falling back to default profiles: local
위와같이 No active profile set, falling back to default profiles: local 로 설정 된다.
end.
'Spring > Spring Boot(스프링 부트)' 카테고리의 다른 글
Spring Boot 앱 빌드하고 실행하기 with jpa, h2 (0) | 2018.12.11 |
---|---|
스프링 부트 API 빌드 & 테스트 (0) | 2018.11.30 |
스프링부트 spring.profiles.active에 default값 설정하기 (0) | 2018.11.16 |
Spring Boot Controller를 만들고 Test하기 (0) | 2018.08.17 |
spring boot logback 환경별(dev, qa, prod)설정, 끄는법 (2) | 2018.08.06 |
AWS Elastic Beanstalk용 Spring Boot 샘플 (0) | 2018.06.29 |