프레임워크
-
Kotlin & Spring 으로 Entity 생성하기프레임워크/Spring Boot 2024. 7. 1. 21:01
자바로 spring을 시작했는데, 회사에서는 코틀린을 쓰게 되었습니다~비슷할 거라고 생각하고 작업을 하지만, 예상치 못한 곳에서 번거로움이 있어서 업무 속도가 안나옵니다! ㅠ어떻게 하는게 좋을까 고민을 해보며 글을 적어봅니다! 1. 주 생성자를 사용해서 엔티티 생성이 방법이 처음 사용한 방법이고 가장 기본적인 방법이라고 생각이 들었습니다.@Entity@Table(name = "lectures")class Lecture( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "lecture_id") val lectureId: Long, @Column(name = "lecture_name", nullable..
-
ServletInputStream은 1번만 읽을 수 있다프레임워크/Spring Boot 2024. 5. 8. 23:36
아래의 글은 다음과 같은 순서로 작성되었습니다.1. 예외의 발생2. 공식 문서에서 단서 찾기3. BufferedReader 동작 확인하기4. 그래도 2번 읽고 싶다면?5. 정리하기 1. 예외의 발생회원가입을 Spring Security의 필터 체인을 사용해서 구현 하고 있습니다. 첫 번째 필터에서 input에 대한 validation 처리를 위해서 request에서 body 정보를 읽습니다. 적절한 요청은 두 번째 필터로 전달을 하고, 회원가입 로직을 가지고 있는 서비스를 주입받아서 사용하려고 합니다.이 때, 필터 간의 데이터 전달을 위한 별도의 dto를 만들지 않기 위해서 기존의 리퀘스트에서 한번 더 바디를 읽으려고 합니다. 하지만 기대와 다르게 예외가 발생합니다? 2. 공식 문서에서 단서 찾..
-
필터에서 발생하는 예외 처리하기프레임워크/Spring Boot 2024. 5. 7. 23:45
Http 통신 중에 발생하는 예외를 처리하던 중 만난 이슈를 적어봅니다.필터에서 발생하는 예외 처리에 관한 내용입니다. 1. 예외가 발생하는 상황인증서버에서 유저 서버로부터 유저 정보를 가져오는 코드의 일부입니다.3개의 catch 문을 가지고 있는데 각각 매칭되는 유저가 없는 경우, 유저 서버의 동작에 문제 있을 때 그리고 그 외의 모든 문제의 경우를 나눠서 처리하고 있습니다. 문제의 발생은 이렇습니다.유저 서버를 실행하지 않은 상태로 ResourceAccessException을 발생시키고 적절한 처리를 하려고 ControlleAdvice를 정의해주었습니다. 하지만 advice에 걸리지 않고 여전히 프론트에서 에러 메세지를 바로 보는 상황이 발생합니다. 왜 예외를 못잡는가 고민하던 중 ...컨트롤러 어..
-
Spring Security 다이어그램으로 flow 정리하기프레임워크/Spring Boot 2024. 5. 7. 02:15
이번에는 충분한 시간가지고 학습할 수 있는 상황이기 때문에 구현에 급급하기 보다는 이해를 하면서 가는 방향을 선택해봅니다 ㅎㅎ디버거로 열심히 따라다니면서 그려보았습니다. 덕분에 흐름이 머릿 속에 잡힌 것 같아 만족스럽습니다 ㅎㅎ 1. ID/PW를 사용해서 로그인 유저의 입력을 기반으로 Authentication을 구현하는 객체를 만들어서 사용합니다.서버 측의 유저 정보를 UserDetails 형태로 준비합니다.둘을 비교하여 적절한 id / pw를 유저가 입력했는지 확인합니다. 노란색으로 표시된 클래스는 커스터마이징이 된 클래스입니다. DaoAuthenticationProvider에서 유저가 입력한 id/pw 와 서버 측의 유저 정보를 비교합니다. 2. Oauth를 사용하는 로그인 기본적으로 Auth..
-
SecurityFilterChain을 여러개 쓰고자 한다면 securityMatcher!프레임워크/Spring Boot 2024. 5. 3. 17:43
스프링 문서를 돌고 돌다 찾은 키워드를 기록하고자 글을 적습니다. 시큐리티 공식 문서에 보면 경로에 맞는 적절한 필터체인을 구현해서 쓰라고 안내합니다. 하지만 어떻게가 빠져있습니다..밑으로 내려가면 Order를 정해서 사용할 수 있다고는 하나, Order를 사용해서 FilterChain을 구분하는 방법은 경로를 분리하기 위함이라기 보다는, 동일한 경로 내에서 우선순위를 정하는 용도가 아닐까 합니다. 그래서 돌고 돌다가 문서의 다른 곳에서 securityMatcher 메소드를 찾았습니다.3번에 보면 applicable only to 라는 문구가 있군요. 그리하여 id/pw 로그인 경로와 Oauth 로그인 경로를 분리해보았습니다.이후에 Oauth 관련 설정 내용이 많아진다면 Oauth Config는..
-
RestTemplate는 응답 객체를 LinkedHashMap으로 파싱한다프레임워크/Spring Boot 2024. 5. 2. 15:00
RestTemplate으로 User서비스에서 데이터를 받아오는 과정에서 발생한 이슈를 정리합니다. 몇 줄 안되는 간단한 코드에서 생각보다 많은 케이스를 만나고 있습니다 ㅎㅎ분명히 응답이 잘 오는 것을 result 를 log로 찍어서 확인했는데. catch 문이 실행됩니다? 저의 응답 객체의 모양은 이렇습니다.성공시 result에 데이터가 담기고, 실패시 에러에 데이터가 담겨서 전달됩니다. 그런데 getResult() 를 하면 java.lang.ClassCastException 예외가 발생합니다.예외를 살펴보면 LinkedHashMap을 AuthUserDetails로 캐스트 할 수 없다고 합니다. 첫 depth의 CustomResponse 는 잘 파싱이 되었는데, 두번째 depth는 주어진 타입이아..
-
RestTemplate은 4xx를 예외로 처리한다.프레임워크/Spring Boot 2024. 5. 2. 02:25
RestTemplate 사용 중에 서버로부터 응답이 반환되어도 예외가 발생하는 것이 낯설어 기록하여봅니다. 다음의 순서로 작성되었습니다.1. 응답 객체의 형태2. 404를 반환 받을 때 1. 응답 객체의 형태현재 User 서버는 Request를 받아서 실행 중에 이슈가 생기면 advice를 통해서 적절한 응답을 반환하고 있습니다. 성공 케이스와 실패 케이스 모두 동일한 인터페이스를 사용해서 반환하고 있습니다.성공인 경우 result에 데이터가 들어가고, 예외가 발생한 경우는 error에 에러 객체를 넣어서 전달합니다. 2. 404를 반환받을 때이상함을 느낀 코드는 아래와 같습니다.restTemplate을 사용해서 User 데이터를 가져오려고 하고 있습니다. 요청한 유저가 존재하지 않는 경우를 처리하..
-
SpringBootApplication이 필요한 bean을 찾지 못하는 경우프레임워크/Spring Boot 2024. 4. 25. 00:01
싱글 모듈 형태로 작성된 프로젝트를 멀티 모듈의 형태로 변경 중에 이슈를 해결한 기록을 적어봅니다.새로 분리한 모듈이 다른 모듈에서 생성하는 bean을 인지 하지 못하는 이슈입니다.프로젝트의 실행과 테스트의 실행 두 부분으로 나눠서 살펴보겠습니다. 이 글은 다음과 같이 진행됩니다.1. 프로젝트의 실행2. 테스트 코드의 실행3. @SpringBootApplication vs @ComponentScan4. @WebMvcTest 1. 프로젝트의 실행quiz_service에 있던 RestTemplate관련 설정을 global 프로젝트로 옮겨주었습니다. 헌데 옮기고 나니 quiz_service가 실행될 때 restTemplate bean을 찾지 못하게 되었습니다. 컴포넌트 스캔 시에 global을 스캔하지 않는..