Spring Boot Admin Server, Client config 설정하기

이미지
 Spring Boot로 많은 프로젝트를 진행하게 됩니다. 많은 모니터링 도구가 있지만, Spring Boot 어플리케이션을 쉽게 모니터링 할 수 있는 방법을 소개하려고 합니다.   코드 중심으로 살펴보겠습니다. 1. 어드민 서버 구축 1-1. 디펜던시 추가 dependencies { // https://mvnrepository.com/artifact/de.codecentric/spring-boot-admin-starter-server implementation 'de.codecentric:spring-boot-admin-starter-server:2.5.4' } 1-2. 어드민 서버 설정 활성화 @SpringBootApplication @EnableAdminServer public class ServerApplication { public static void main (String[] args) { SpringApplication. run (ServerApplication. class, args) ; } } EnableAdminServer를 하면 됩니다. 2. 클라이언트 서버 설정  예제는 book-client, member-client 2가지 클라이언트, member-client가 2개의 인스턴스 실행으로 작성했습니다.  2-1 디펜던시 추가 dependencies { // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web implementation 'org.springframework.boot:spring-boot-starter-web:2.5.4' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator implementation 'org.spring...

스프링 부트 프로파일 환경 설정 방법

Spring boot profile 환경 설정 방법


토이 프로젝트가 아닌 사용자에게 서비스할 프로젝트인 경우 개발 환경과 서비스 환경을 분리해서 구성해야할 필요가 있습니다.

스프링 부트 프로젝트 생성

스프링 부트 프로젝트 세팅하기
스프링 부트 프로젝트를 쉽게 세팅할 수 있다. 간단히 웹 디펜던시만 추가하였습니다. (세팅하는데 없어도 상관없습니다.)

파일을 분리하는 방법과 하나의 파일에 환경별로 작성하는 방법이 있습니다.

1. 파일을 분리하는 방법

환경 설정 파일 예시

파일 생성 및 구성

위의 이미지처럼 환경별로 파일을 생성합니다.
application-{환경}.properties
예시는 로컬, 개발, 실서비스 3가지로 작성되었습니다.

#application-local.properties
logging.level.org.springframework=DEBUG
#application-dev.properties
logging.level.org.springframework=INFO
#application-prod.properties
logging.level.org.springframework=WARN

실행할 때 환경을 세팅하는 방법


1. 설정 파일에 정의하기
#application.properties
spring.profiles.active=local
2. 실행할 때 주입하기
실행 환경 주입

Active profiles: 원하는 환경

3. mvn 빌드시 설정
mvn -Dspring.profiles.active=prod spring-boot:run &


2. 하나의 파일에 환경별로 작성하는 방법

#application.yml
---
spring:
profiles: local, dev
logging:
level:
org.springframework: DEBUG
---
spring:
profiles: test
logging:
level:
org.springframework: INFO
---
spring:
profiles: prod
logging:
level:
org.springframework: WARN

spring:profiles: 환경을 정의하고 다음에 원하는 설정을 작성하면 됩니다.

#application.yml
---
spring:
config:
activate:
on-profile: local, dev
logging:
level:
org.springframework: DEBUG
---
spring:
config:
activate:
on-profile: test
logging:
level:
org.springframework: INFO
---
spring:
config:
activate:
on-profile: prod
logging:
level:
org.springframework: WARN
Spring boot 2.4버전이후 속성이 spring.config.activate.on-profile 로 이동되었습니다.





댓글

이 블로그의 인기 게시물

Spring boot redis cache config

Spring boot redis RedisTemplate

MySQL PK 중복 (duplicate key ) 해결 방법