본문 바로가기

spring

Unit Test - ParameterizedTest Source annotation @ValueSource -> Array of values: Strings, ints, doubles, floats etc @CsvSource -> Array of CSV String values @CsvFileSource -> CSV values read from a file @EnumSource -> Enum constant values @MethodSoruce -> Custom method for providing values //sample @DispleName("Testing with Small data file") @PrameterizedTest(name="value={0}, expected={1}") //0번째 인덱스의 값이 1 @CsvFileSource(res.. 더보기
Java Conditional Unit Test @Test @Disabled("Don't run until JIRA #123 is resolved") void testDisabled(){ // } @Test @EnabledOnOs(OS.WINDOWS) void testForWindowsOnly(){ } @Test @EnabledOnOs(OS.MAC) void testForMacOnly(){ } @Test @EnabledOnOs({OS.MAC,OS.WINDOWS}) void testForMacAndWindowsOnly(){ } @Test @EnabledOnOs(OS.LINUX) void testForLinuxOnly(){ } @Test @EnabledOnJre(JRE.JAVA_17) void testForJava17(){ } @Test @EnabledO.. 더보기
spring aop AOP DI 추가 implementation 'org.springframework.boot:spring-boot-starter-aop' controller @Slf4j @RestController @RequestMapping("/api") public class RestApiController { @GetMapping("/get/{id}") public String get(@PathVariable Long id, @RequestParam String name){ return String.format("%s-%s",id, name); } @PostMapping("/post") public UserDto post(@RequestBody UserDto userDto){ return userDto; } @Dec.. 더보기
Spring mvc async rest api /* 결제 내역 조회시 해당 결제 내역에 사용자 정보를 포함해야 한다. 사용자 정보 조회를 위해 결제아이디로 사용자 정보를 조회 후 결제 정보에 조인 시켜야 한다. 해당 프로세스를 비동기적으로 처리 하도록 한다. */ Enable Async and config thread pool @EnableAsync @Configuration public class BeanConfig { /** * @see https://kapentaz.github.io/spring/Spring-ThreadPoolTaskExecutor-%EC%84%A4%EC%A0%95/# */ @Bean("accounting-async-thread") public Executor asyncThread(){ ThreadPoolTaskExecutor .. 더보기
Spring mvc async rest api /* 결제 내역 조회시 해당 결제 내역에 사용자 정보를 포함해야 한다. 사용자 정보 조회를 위해 결제아이디로 사용자 정보를 조회 후 결제 정보에 조인 시켜야 한다. 해당 프로세스를 비동기적으로 처리 하도록 한다. */ Enable Async and config thread pool @EnableAsync @Configuration public class BeanConfig { /** * @see https://kapentaz.github.io/spring/Spring-ThreadPoolTaskExecutor-%EC%84%A4%EC%A0%95/# */ @Bean("accounting-async-thread") public Executor asyncThread(){ ThreadPoolTaskExecutor .. 더보기
ModelMapper 를 사용하여 객체 컨버팅 하기 서로 다른 클래스의 값을 복사 해주는 라이브러리이며, 필드명 일치 혹은 유사 필드 , 값일 없는 필드 복사 스킵 등 을 쉽게 도와 주는 라이브러리이다. 사용을 위한 dependency org.modelmapper modelmapper 2.3.8 ​ 사용 방법 //A 클래스를 B 클래스로 컨버팅 예제 ModelMapper modelMapper = new ModelMapper(); //MatchingStrategies 는 여러가지가 존재하며 상황에 맞게 사용 하도록 한다. //여기서는 필드명 완전일치 할 경우에만 진행 하도록 한다. modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); B b = modelMapper.ma.. 더보기
spring factory pattern Factory 패턴: 하위 클래스가 어떤 객체를 생성할지를 결정 하도록 하는 패턴. 스프링에서 빈을 컬렉션으로 주입할 수 있다. //타입 public enum AuthenticationType { PASSWORD, DEVICE, FIDO } //인터페이스 public interface AuthenticationService { AuthenticationType getAuthentiicationType(); void validateAuthentication(); } //비밀번호 인증구현체 @Slf4j @Service public class AuthenticationPasswordService implements AuthenticationService{ @Override public Authenticatio.. 더보기
React Stream create and test //배열로 부터 리액트 타입 생성 public Flux creatFluxFromArray(){ String[] countryArray = new String[] { "Korea","America","China","Canada" }; Flux countryFlux = Flux.fromArray(countryArray); return countryFlux; } // 컬렉션 타입으로부터 리액트 타입 생성 public Flux creatFluxFromIterable(){ List countryList = Arrays.asList("Korea","America","China","Canada"); Flux countryFlux = Flux.fromIterable(countryList); return countryF.. 더보기