본문 바로가기

spring10

resilience4j: CircuitBreaker configuration 간단 정리 CircuitBreaker의 설정 항목들에 대한 간단 정리이다. 나머지 항목은 레퍼런스 문서를 참고하자 - https://resilience4j.readme.io/docs/circuitbreaker#create-and-configure-a-circuitbreaker resilience4j: circuitbreaker: instances: licenseService: # circuit breaker 이름 # health endpoint 를 통해 configuration 정보를 노출할지 여부. default false. registerHealthIndicator: true # 슬라이딩 윈도우의 타입(COUNT_BASED or TIME_BASED). default COUNT_BASED. # 슬라이딩 윈도우는 .. 2022. 8. 18.
p8s: Spring Boot에서 Prometheus 메트릭 노출하기 dependency를 추가해 주는 것으로 충분하다. 하지만 endpoint의 prefix가 actuator 경로 하위로 한정된다(actuator 경로를 변경하는 방법은 있지만, 하위 경로에 속해야 한다는 제약을 벗어나는 다른 방법을 발견하지 못했음). implementation 'org.springframework.boot:spring-boot-starter-actuator' ... // "/actuator/prometheus" 에 p8s 메트릭을 노출해준다. implementation 'io.micrometer:micrometer-registry-prometheus' actuator의 하위 경로가 아닌 endpoint로 메트릭을 노출하려면 다음과 같이 컨트롤러를 구현한다. "/metrics"로 노출하는.. 2022. 8. 18.
Spring: @DataJpaTest JPA 컴포넌트의 테스트에만 포커스하는 애너테이션이다. auto-configuration을 비활성화시키며, JPA 테스트에 필요한 configuration만 적용된다. 각 테스트는 트랜잭션이 적용되어 실행되며, 테스트가 끝나면 롤백된다. 기본적으로 인메모리 데이터베이스가 사용되기 때문에 @AutoConfigureTestDatabase(replace = Replace.NONE) 으로 오버라이드 해야 한다. 실행되는 SQL의 로깅은 spring.jpa.show-sql 설정에 따르지만, 설정이 없으면 true 가 기본값이다. @ActiveProfiles 로 테스트 환경을 명시하자. application-{테스트}.yml 도 준비하자. 예) "springtest" @ContextConfiguration 를 사용.. 2022. 8. 14.
Validation with Spring Boot - the Complete Guide 원문: Validation with Spring Boot - the Complete Guide Bean Validation 은 Java 에코시스템에서 유효성 검증 로직을 구현하기 위한 사실상의 표준이다. Spring 및 Spring Boot와 잘 통합되어있다. 그러나 몇 가지 함정이 있다. 이 자습서에서는 모든 주요 유효성 검사 사용 사례와 각각에 대한 예제 코드를 살펴본다. 예제 코드 이 글은 동작하는 예제 코드가 GitHub으로 함께 제공된다 . Spring Boot Validation Starter 사용하기 Spring Boot의 Bean Validation 지원은 validation starter로 제공되며, 다음과 같이 프로젝트에 포함할 수 있다(Gradle). implementation(&#3.. 2022. 8. 14.
Spring: @ConfigurationProperties 참고: https://www.baeldung.com/configuration-properties-in-spring-boot @Component 애너테이션을 프로퍼티 클래스에 적용한다. Spring Boot 2.2 부터는 클래스패스를 스캔해서 @ConfigurationProperties 를 등록해 주기 때문에 @Component , @EnableConfigurationProperties 를 사용할 필요가 없다고 한다.⁠ @EnableConfigurationProperties(propertyClass.class) 를 @Configuration 클래스에 적용할 필요는 없다. 프로퍼티 클래스에는 기본 생성자, getter, setter가 필요하다. 스프링은 자바빈의 setter를 사용하여 프로퍼티를 채워준다. .. 2022. 8. 14.