티스토리 뷰

스프링부트 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.

 

 

 

 

 

 

 

 

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함