Tech/SpringBoot
-
ModelMapper 를 사용하여 객체 컨버팅 하기Tech/SpringBoot 2021. 5. 23. 12:14
서로 다른 클래스의 값을 복사 해주는 라이브러리이며, 필드명 일치 혹은 유사 필드 , 값일 없는 필드 복사 스킵 등 을 쉽게 도와 주는 라이브러리이다. 사용을 위한 dependency org.modelmapper modelmapper 2.3.8 사용 방법 //A 클래스를 B 클래스로 컨버팅 예제 ModelMapper modelMapper = new ModelMapper(); //MatchingStrategies 는 여러가지가 존재하며 상황에 맞게 사용 하도록 한다. //여기서는 필드명 완전일치 할 경우에만 진행 하도록 한다. modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); B b = modelMapper.ma..
-
Spring AOPTech/SpringBoot 2020. 12. 6. 15:24
관점 지향 프로그램 예: 보안 관련된 관심사, API 성능로깅, 트랜잭션 관리,요청 로깅 등 Aspect: 관심사를 모듈화 한것이다. 여러 클래스에 걸쳐 코드를 분산하는 대신 관심사를 다루는 로직을 하나의 Aspect 에 넣는다. 예: isValidatedMember() 와 같이 검증 메서드를 여러 클래스에 초기 진입부에서 검증 스프링에서 클래스에 Aspect 를 구현 할 수 있으며, @Aspect 어노테이션을 적용 할수있다. dependency: org.springframework.boot:spring-boot-starter-aop AOP 적용 전: classDemoA -> methodDemoA( isValidatedMemebr() ) classDemoB -> methodDemoB( isValidate..
-
spring factory patternTech/SpringBoot 2020. 10. 19. 23:46
Factory 패턴: 하위 클래스가 어떤 객체를 생성할지를 결정 하도록 하는 패턴. 스프링에서 빈을 컬렉션으로 주입할 수 있다. //타입 public enum AuthenticationType { PASSWORD, DEVICE, FIDO } //인터페이스 public interface AuthenticationService { AuthenticationType getAuthentiicationType(); void validateAuthentication(); } //비밀번호 인증구현체 @Slf4j @Service public class AuthenticationPasswordService implements AuthenticationService{ @Override public Authenticatio..
-
spring webflux swagger configTech/SpringBoot 2020. 8. 31. 21:18
- spring boot version org.springframework.boot spring-boot-starter-parent 2.3.3.RELEASE - swagger maven dependency io.springfox springfox-boot-starter 3.0.0 io.springfox springfox-oas 3.0.0 - swagger config @Configuration @EnableOpenApi public class SwaggerConfig { @Bean public Docket apiConfig() { return new Docket(DocumentationType.SWAGGER_2) .groupName("version_1.0") .enable(true) .select() ...
-
React Stream create and testTech/SpringBoot 2020. 8. 24. 19:14
//배열로 부터 리액트 타입 생성 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..
-
Spring boot kafka demo with docker-composeTech/SpringBoot 2020. 7. 20. 21:15
spring boot kafka demo with docker ref kafka with springboot description kafka ref kafka 는 pub-sub 모델을 기반으로 동작한다. 구성요소: zookeeper: producer 와 consumer 를 관리한다. producer: topic 의 메시지 생성후 해당 메시지를 broker 에 전달 consumer: topic 을 subscribe 한다. 메시지를 pull 방식으로 broker 로부터 가져오기 때문에 batch consumer 구현 가능. broker: topic 을 기준으로 메시지 관리 전달받은 메시지를 topic 별로 분류하여 적재 topic: partition 단위로 구성 된다. 클러스터 서버에 분산 저장할 경우 pa..
-
Flux and MonoTech/SpringBoot 2020. 7. 14. 18:52
Spring Reactive 를 위해 flux and Mono 에 대해 간단하게 테스트 해보도록 하고 기록으로 남기도록 한다. private final static String[] countries = new String[]{"Korea","China","America","Canada"}; private final static Flux countiesFlux = Flux.just("Korea","China","America","Canada"); /** * create flux */ @Test public void createFluxWithJustAndVerify(){ //subscribe 를 사용하여 구독 및 출력 하도록 한다. countiesFlux.subscribe(s->{ System.out.pri..
-
how to generate random number or Alphabetic in javaTech/SpringBoot 2020. 4. 30. 19:48
apache.commons-lang3 compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4' tutorial - generate sample code: //[a-zA-Z] -> RandomStringUtils.randomAlphabetic(count) //[0-9] -> RandomStringUtils.randomNumeric(count) //[a-zA-Z0-9] -> RandomStringUtils.randomAlphanumeric(count) String.format("%s-%s-%s", RandomStringUtils.randomAlphabetic(5), RandomStringUtils.randomNumeric(5), R..
-
Object List multiple field compare and removeTech/SpringBoot 2020. 2. 25. 09:49
class Product { private String code; private String name; private String category; private long price; } List products = Arrays.asList(); //코드,이름 카테고리 3개의 필드가 중복되는 상품 제거. Collection removes = products .stream() .collecti(toMap( p -> Arrays.asList(p.getCode(),p.getName(),p.getCategory()), Function.identity(),(p1,p2) -> p1)) .values();
-
Java Object Stream group by multiple field and map in map to listTech/SpringBoot 2020. 1. 5. 12:45
java stream 을 사용하여 객체 리스트를 여러개 필드로 그룹핑 후 맵형태로 생성 후 리스트로 출력 해보도록 한다. 원본 리스트를 그룹핑 하여 출력되는 최종 결과는 아래 그림과 같다. List courseList = Arrays.asList( Course.builder() .code("A0001") .subject("Math") .semester("First") .price(10000l) .build(), Course.builder() .code("A0001") .subject("Math") .semester("Second") .price(10000l) .build(), Course.builder() .code("A0005") .subject("OperatingSystem") .semester("S..