본문 바로가기

springboot

Quartz를 이용한 클러스터링 설정과 구현 방법 Spring Boot와 Quartz 스케줄러를 사용하여, 여러 서비스 인스턴스에서의 클러스터링을 구현하는 방법을 설명합니다. Quartz의 클러스터링 기능을 활성화하여, 여러 서비스 인스턴스가 동일한 작업 스케줄을 공유하고, 한 인스턴스에서 실패한 작업을 다른 인스턴스에서 이어받을 수 있도록 구성합니다. 의존성 추가 implementation 'org.springframework.boot:spring-boot-starter-quartz' application.properties 설정 application.properties 파일에 Quartz와 데이터베이스 관련 설정을 추가합니다. 이 설정은 Quartz가 클러스터링 모드로 작동하도록 구성하는 데 필요합니다. # 데이터베이스 설정 spring.dataso.. 더보기
마이크로서비스 추적을 위한 Spring Cloud Sleuth와 Zipkin 사용예제 Spring Cloud Sleuth는 Spring Cloud 프레임워크의 일부로, 마이크로서비스 아키텍처에서 서비스 간의 요청 추적을 돕는 라이브러리입니다. 이를 통해 개발자는 마이크로서비스 간의 요청이 어떻게 흘러가는지, 각 서비스에서 소요되는 시간 등을 쉽게 확인하고 문제를 진단할 수 있습니다. Spring Cloud Sleuth는 주로 다음과 같은 방법으로 작동합니다: 각 마이크로서비스의 요청과 응답에 유니크한 ID를 부여하여 추적합니다. 서비스 호출 체인을 통해 각 서비스의 응답 시간과 상태를 로깅합니다. 이 정보를 이용하여 시각화 도구 (예: Zipkin)에 데이터를 전송하여, 서비스 간의 호출 관계와 응답 시간을 시각적으로 확인할 수 있게 해줍니다. Spring Cloud Sleuth Spri.. 더보기
Spring boot Private field and method Test ReflectionTestUtils를 이용하여 private field or method 를 테스트 할 수 있다. public class Student { private int id; private String getFirstNameAndId(){ return getFirstName() + " " + getId(); } } @SpringBootTest class StudentTest { @Autowired Student student; @BeforeEach void studentBeforeEach(){ student.setFirstName("Eric"); student.setLastName("Roby"); student.setEmailAddress("asdfa@asdf.com"); student.setS.. 더보기
Spring boot Throwing Exception test @SpringBootTest class StudentRepositoryTest { @Autowired Student student; @Autowired StudentGrades studentGrades; @MockBean private StudentRepository studentRepository; @Autowired private StudentService studentService; @Autowired private ApplicationContext context; @DisplayName("Throw runtime error") @Test void throwRuntimeError() { Student nullStudent = (Student)context.getBean("Student"); doTh.. 더보기
Spring boot @MockBean Example @SpringBootTest class StudentRepositoryTest { @Autowired Student student; @Autowired StudentGrades studentGrades; @MockBean private StudentRepository studentRepository; @Autowired private StudentService studentService; @BeforeEach void beforeEach() { student.setFirstName("Eric"); student.setLastName("King"); student.setEmailAddress("eric.roby@asdf.com"); student.setStudentGrades(studentGrades); .. 더보기
Spring boot @MockBean @MockBean - includes Mockito @Mock functionality - also adds mock bean to if existing bean is there, the mock bean will replace it - thus making the mock bean available for injection with @Autowired Using @Mock @SpringBootTest class StudentRepositoryTest { @Mock private StudentRepository studentRepository; @InjectMocks private StudentService studentService; } Using @MockBean @SpringBootTest clas.. 더보기
Spring boot Mockito Example - @Mock & @InjectMocks @SpringBootTest class StudentRepositoryTest { @Autowired Student student; @Autowired StudentGrades studentGrades; @Mock private StudentRepository studentRepository; @InjectMocks // inject mock dependencies private StudentService studentService; @BeforeEach void beforeEach() { student.setFirstName("Eric"); student.setLastName("King"); student.setEmailAddress("eric.roby@asdf.com"); student.setStud.. 더보기
Spring boot Test with Mockito Mocking Framworks mockito easymock jmockit Mockito in spring boot mockito framwork is builtin spring boot dependency -> spring-boot-starter-test Mockito Test Process setup set expectations with mock reponses execute call the method want to test assert check the result and verify that it is expected result verify optionally.. verify calls (how many times called etc..) Mokcito Test in Spring boot .. 더보기