WEB 158

스프링 배치 소개 + 시작

자바 기반 표준 배치 기술이 없어서 탄생함 배치핵심패턴 read = 데이터 베이스, 파일 , 큐에서 다량의 데이터 조회 process = 특정 방법으로 데이터를 가공한다. write = 데이터를 수정된 양식으로 다시 저장한다. ETL(Extract , Transform , Load) 와 유사하다. @EnableBatchProcessing = 스프링 배치가 동작하기 위해 선언해야 하는 어노테이션 총 4개의 설정클래스를 실행시키며 스프링 배치의 모든 초기화 및 실행 구성이 이루어진다. 스프링 부트 배치의 자동 설정 클래스가 실행됨으로 빈으로 등록된 모든 Job을 검색해서 초기화와 동시에 Job을 수행하도록 구성됨 스프링 배치 초기화 설정 클래스 1. BatchAutoConfiguration 스프링 배치가 초..

WEB/Spring Batch 2023.02.16

외부 설정을 이용한 자동 구성

Environment 추상화와 프로퍼티 imports 를 selector 가 로딩을하고 class level @Conditional 을 확인하고 method level(@Bean을 생성하는 팩토리메소드) 의 @Conditional을 확인하게 된다. custom bean구성정보는 개발자가 추가한 (custom tomcat) 팩토리 빈 메소드를 의미한다. 기본 tomcat port를 바꾸고 싶다든지 다양한 property를 변경을 가능하게 한다. 읽어와서 사용을 할 수 있다. getProperty에 넣는 인자는 다음 사진처럼 4가지로 spring boot가 알아서 converting 해서 인식을 하게 된다. 자동 구성에 Environment 프로퍼티 적용 @MySpringBootApplication publ..

WEB/Spring Boot 2023.02.13

자동 구성 기반 애플리케이션 + 조건부 자동 구성

테스트 코드를 이용한 테스트 public class HelloApiTest { @Test void helloApi() { TestRestTemplate rest = new TestRestTemplate(); ResponseEntity res = rest.getForEntity("http://localhost:8080/hello?name={name}", String.class, "Spring"); assertThat(res.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(res.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE)).startsWith(MediaType.TEXT_PLAIN_VALUE); assertThat(re..

WEB/Spring Boot 2023.02.09

독립 실행형 서블릿 애플리케이션

public class SpringbootmineApplication { public static void main(String[] args) { ServletWebServerFactory serverFactory = new TomcatServletWebServerFactory(); WebServer webServer = serverFactory.getWebServer(); webServer.start(); } } @SpringBootApplication annotation 없이 직접 tomcat을 기동 시키는 과정이다. public class HellobootApplication { public static void main(String[] args) { GenericApplicationContext ..

WEB/Spring Boot 2023.02.02

행동 관련 디자인 패턴

책임 연쇄 패턴 public static void main(String[] args) { RequestHandler chain = new AuthRequestHandler(new LoggingRequestHandler(new PrintRequestHandler(null))); Client client = new Client(chain); client.doWork(); } spring security에서 쓰이는 FilterChain 처럼 여러 handler chain을 만든것이다. 하나의 클래스가 하나의 책임을 지니고 조건에 맞으면 일을 처리하고 다름 handler에게 넘겨주는 방식이다. @WebFilter(urlPatterns = "/hello") public class MyFilter implement..

WEB/Design Pattern 2023.01.29

구조 관련 디자인 패턴

어댑터 패턴 기존에는 Account는 security package(건드릴수없는 코드, library) 에 있었던 LoginHandler를 쓸 수 없었다. Login Handler는 UserDetailsService와 연관되어있고 UserDetailsService는 UserDetails를 return 하기 때문이다. 우리가 원하는 것은 AccountService - UserDetailService , Account - UserDetails 처럼 연결하고 싶다 하지만 AccountUserDetailsService , AccountUserDetails 가 중간에 adapter 역할을 하여 client가 LoginHandler를 원할하게 사용이 가능해졌다. public static void main(Strin..

WEB/Design Pattern 2023.01.27

객체 생성 관련 디자인 패턴

싱글턴 패턴 2 public class Settings3 { private static volatile Settings3 instance; private Settings3() { } public static Settings3 getInstance() { if (instance == null) { synchronized (Settings3.class) { if (instance == null) { instance = new Settings3(); } } } return instance; } } instance가 없는 경우에 multithread 환경에서만 synchronized가 락을 잡고 안전하게 싱글톤을 유지하게 되고 평상시 상황에는 락없이 바로 return 하게 된다. 또한 해당 instance가 필..

WEB/Design Pattern 2023.01.26

실전프로젝트 - 인가 프로세스 DB 연동 서비스 계층 구현

Method 방식 - 개요 서비스 계층의 인가처리 방식 1. 화면 , 메뉴 단위가 아닌 기능 단위로 인가처리 2. 메소드 처리 전.후 로 보안 검사 수행하여 인가처리 AOP 기반으로 동작 프록시와 어드바이스로 메소드 인가처리 수행 보안 설정 방식 어노테이션 권한 설정 방식 = @PreAuthorize("hasRole('USER')"), @PostAuthorize("hasRole('USER')"), @Secured("ROLE_USER") 맵 기반 권한 설정 방식 = 맵 기반 방식으로 외부와 연동하여 메소드 보안 설정 구현 어노테이션 권한 설정 - @PreAuthorize , @PostAuthorize , @Secured , @RolesAllowed @PreAuthorize, @PostAuthorize Sp..

WEB/Security 2023.01.20