본문 바로가기

spring13

국제화처리를 위한 messageSource 빈에 대한 이슈 스프링 부트가 아닌 스프링 프로젝트에서는 applicationContext.xml 와 servlet-context.xml 가 따로 있다. applicationContext.xml 에서는 @Service @Repository @Component 빈 등록과 dataSource 관련 빈 등록 등을 작업. servlet-context.xml 에서는 web 과 관련된 설정들 @Controller 빈등록과 mvc 관련 config, 뷰리졸버 관련 빈 등록 등을 작업. 처음엔 messageSource 빈 등록을 servlet-context.xml 에서 했다. 보여지는 메세지만 로케일에 맞게 다국어 처리하는 거니 web 영역이라고 판단했다. 그런데 applicationContext.xml 에 등록된 빈은 servlet.. 2021. 6. 18.
WebClient 사용할때 주의 (2편) exchangeToMono 를 쓸 때 cf) WebClient 사용할때 주의 (1편) 에서 exchange 를 쓸 때 주의할 점을 하나 소개했는데, 이제 exchange는 deprecated 되었고 대신 exchangeToMono 나 exchangeToFlux 를 써야한다. 1) doOnSuccess 와 onErrorResume .exchangeToMono(clientResponse -> clientResponse.toEntity(String.class)) .doOnSuccess(clientResponse -> { if (clientResponse.getStatusCode() != HttpStatus.OK) { throw new RuntimeException("error"); } } ) .onErrorR.. 2021. 6. 10.
reflection 사용해서 api 문서화 내가 담당하는 api 서버에서 제공하는 외부/내부 api들을 문서화 하기로 했다. 일반적으로 wiki나 github 등에 문서화를 하면 코드 변경을 계속 반영하기 어려운 문제가 있다. 그걸 해결해주는 대표적인 api 도큐멘트로 swagger 가 있다. swagger 관련 애노테이션을 추가함으로써 쉽게 도큐멘트 페이지를 제공할 수 있다. 하지만 우리팀은 아래 두가지 이유 때문에 직접 구현하기로 결정했다. 1. api 도큐멘트 다국어 국제화 처리 2. 심플하게 꼭 필요한 정보만 제공 하고 애노테이션 하나만 사용 그리고 직접 구현하기 위해서는 자바 리플렉션 기법이 필요했다. 자바 리플렉션 이란 리플렉션은 자바의 클래스, 메서드, 필드 등의 정보를 확인할 수 있는 API 다. Class 객체가 주어지면 그 클래.. 2021. 5. 2.
Spring Cloud Gateway CORS 주의사항 CORS 요청을 받기 위해 서버가 해줘야 하는 작업들이 있다. 그런데 Spring Cloud Gateway 는 프록시 서버이기 때문에 조금 더 신경써야 하는 부분이 있어 정리했다. ※ CORS 기본 개념까지 같이 설명하기엔 글이 너무 길어져서 안다는 전제로 작성했다. 먼저 Spring Cloud Gateway 는 CORS 요청을 디폴트로 막는다. CORS 허용하는 방법 1) CorsWebFilter 첫번째 방법은 CorsWebFilter 를 이용하는 것인데, 헷갈리지 말아야 될 게 있다. CorsWebFilter 는 Spring Cloud Gateway 에서 제공하는 필터가 아니다. org.springframework.web.cors.reactive 에서 제공하는 필터다. 그래서 Spring Cloud .. 2021. 1. 24.
useInsecureTrustManager 옵션 Spring Cloud Gateway 에서 useInsecureTrustManager 옵션 디폴트는 false 다. Spring Cloud Gateway 가이드는 보안 이유로 true로 설정하는건 production 에 적합하지 않다고 한다. cloud.spring.io/spring-cloud-gateway/multi/multi__tls_ssl.html 7. TLS / SSL The Gateway can listen for requests on https by following the usual Spring server configuration. Example: Gateway routes can be routed to both http and https backends. If routing to a ht.. 2021. 1. 20.
개발 이슈 모음 1. Spring Security X-Frame-Options 이슈 Default Security Headers Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Content-Type-Options: nosniff Strict-Transport-Security: max-age=31536000 ; includeSubDomains X-Frame-Options: DENY X-XSS-Protection: 1; mode=block cf) Strict-Transport-Security는 HTTPS 요청일때만 추가된다. X-Frame-Options: DENY response header에 X-Frame.. 2021. 1. 19.