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...

LocalDateTime atStartOfDay 날짜 시작 시간으로

개발하다보면 해당 날짜에 00시00분00초가 필요한 경우가 많습니다. 예를들어 오늘 작성된 댓글을 조회하고 싶은경우 날짜의 시작부터 다음날까지 조회를 하게 됩니다. 날짜만 사용하는 경우가 되지요.

이때 필요한 함수가 atStartOfDay입니다. 함수명에서 잘 나타나있는데요. 이 함수는 LocalDate에 있기때문에 한번 변환과정이 필요합니다.


예제

LocalDateTime ldt = LocalDateTime.now();
System.out.println(ldt);
LocalDateTime onlyDate = ldt.toLocalDate().atStartOfDay();
System.out.println(onlyDate);

실행결과

2022-09-06T22:25:56.904512100
2022-09-06T00:00


시작날짜 종료날짜 예제

LocalDateTime ldt = LocalDateTime.now();
System.out.println(ldt);
LocalDateTime startDate = ldt.toLocalDate().atStartOfDay();
LocalDateTime endDate = startDate.plusDays(1).toLocalDate().atStartOfDay();
System.out.println("startDate === " + startDate);
System.out.println("endDate === " + endDate);

plusDays를 활용하여 내일날짜를 가져옵니다.


실행결과

2022-09-06T23:35:04.765255100
startDate === 2022-09-06T00:00
endDate === 2022-09-07T00:00


댓글

이 블로그의 인기 게시물

Spring boot redis cache config

Spring boot redis RedisTemplate

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