pooney
article thumbnail
Spring boot ServletUriComponentsBuilder
Spring boot 2020. 7. 5. 02:55

Rest API를 구현 하다 보면 사용자로 부터 요청왔을때 특정값을 포함한 uri를 전달해야 하는 상황이 발생할 수 있다. 이떄 사용하는 것이 ServletUriComponentsBuilder이다. ServletUriComponentsBuilder를 통해 적절한 URI를 만들고 요청한 사용자에게 특정값을 포함한 URI를 전달 할 수 있다. ServletUriComponentsBuilder 아래의 방식은 파일업로드 후 파일다운로드 경로를 사용자에게 보내주고자 할 때 자주 사용되는 방법입니다. 지금은 간단한 예제를 만들겠습니다. TestController ServletUriComponentsBuilder.fromCurrentRequest()를 통해 사용자가 요청한 Uri를 가져온 다음 path를 통해 원하는..

Spring boot DispacherServlet이란?
Spring boot 2020. 7. 5. 02:03

DisDispacherServlet을 관리하기 위해 DisDispacherServletAutoConfiguration메소드가 자동으로 실행이된다. 사용자 요청에따른 비즈니스 로직을 처리한 다음에 결과 값을 api를 호출한 쪽에 다시 전달해야한다. 이러한 DisDispacherServlet은 사용자 요청을 처리를 담당하는 일종의 게이트라 생각 할 수 있다. 사용자 요청에 따른 결과값을 반환하기 위해 사용되어지는 AutoConfiguration파일은 HttpMessageConvertersAutoConfiguraion이 사용되어진다. HttpMessageConvertersAutoConfiguraion의 역할은 json형태로 변환 해서 사용자에게 전달하는 역할을 수행한다.

article thumbnail
Spring boot Lombok 활성화
Spring boot 2020. 7. 5. 01:12

Lombok 사용시 비활성화 되어 에러가 나서 불편한 적이 있을 것이다. 이경우 간단한 설정으로 lombok을 활성화 시킴으로써 문제를 해결 할 수 가 있다. 1. [File] - [Settings] - [Compiler] - [Annotation Processors] - Enable annotion processing 활성화

Springboot Junit 사용시 @TestPropertySource 에러
Spring boot 2020. 6. 22. 15:26

설정파일을 읽기 위하여 @TestPropertySource를 사용을 하는데 이때 조심해야하는 상황은 시스템환경변수이다. @TestPropertySource에 경로를 입력하더라도 시스템환경변수가 등록되어있다면 계속 시스템환경변수의 경로를 찾을것이다. 조심조심 ...

Spring boot security 적용시 post 404에러
Spring boot 2020. 6. 16. 15:03

Spring security 적용시 기본적으로 csrf를 막기위하여 활성화 되어 있다 때문에 csrf 체크를 하여 @GetMapping 호출 시 문제가 없지만@PostMapping 호출 시 404에러 발생한다. 이것을 해결 하기 위해서는 Security 설정 파일에서 csrf().disable()를 삽입하면 해결 가능하다. @Override protected void configure(HttpSecurity http) throws Exception { log.info("아래 코드 삽입"); http.csrf().disable(); }

Spring boot @RequestBody 로 JSON 데이터 받을 시 JSON parse error
Spring boot 2020. 5. 19. 22:44

@RequestBody를 사용하여 JSON 데이터를 받으려고 하는데 JSON parse error 에러가 나는 경우가 있다. 이때 살펼 볼것은 더블쿼터이다. 나는 rest api를 테스터하려고 curl을 사용하여 요청을 하였다. 변경전 curl -X POST http://localhost:9090/hi -H "Content-Type: application/json" -d '{"name":"qoqoqo"}' Error 2020-05-19 22:34:00.509 WARN 24768 --- [nio-9090-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotRead..

article thumbnail
Spring boot jsp와 Thymeleaf 사용하기
Spring boot 2020. 5. 16. 03:08

크게 템플릿 엔진은 여러개가 존재한다. 그중 JSP 와 Thymeleaf를 설명한다 우선 spring-boot-devtools를 추가 한후 true를 준다. 이유는 수정작업이 이루어지면 톰켓을 재시작하여 바로 결과를 반영 할 수 있게 도와준다. pom.xml org.springframework.boot spring-boot-devtools runtime true jsp 사용하기 1. application.properties에 아래의 코드 삽입 application.properties #jsp spring.mvc.view.prefix=/WEB-INF/views/ spring.mvc.view.suffix=.jsp 2. pomx.xml에 jasper 와 jstl 삽입 .jsp로 끝나는 확장자는 jasper가 ..

article thumbnail
Spring boot Controller test
Spring boot 2020. 5. 15. 20:15

일반적인 webmvc 테스트이면 mock를 사용해도 되지만 rest controller를 테스트 할 것이기 때문에 아래는 TestRestTemplate을 사용하여 test를 진행했다. Controller 테스트 1. 테스트 할 controller인 HelloController 생성 HelloController package com.example.demo.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @RequestMappin..