전체 글
-
Spring InterceptorSPRING 공부/서블릿 2022. 7. 13. 21:05
인터셉터란? 스프링에서 제공하는 제공하는 기능으로 Dispatcher Servlet과 매핑된 URL의 Controller의 사이에서 존재하며 해당 Controller 호출 전과 후에 요청, 응답을 참조하거나 가공할 수 있는 필터라고 볼 수 있다. 주 용도로는 인증/인가 작업이나, API 호출에대한 로깅, 요청 응답 정보 가공등이 있다. 여기서 의문이 드는점이 있는데, 사실 필터랑 인터셉터랑 무슨 차이가 있냐이다. 1. 관리 주관자가 다르다. 필터 : 웹 Servlet 컨테이너 , 인터셉터: 스프링 컨테이너 2. Request,Response 객체를 새로운 객체로 넣을 수 있나? 필터 : Yes , 인터셉터 : No -> 필터에서는 request,response를 다음 필터로 넘겨주는 필터 체인을 쓰나, ..
-
서블릿 필터SPRING 공부/서블릿 2022. 7. 10. 03:30
필터란 말그대로 지정한 URL 패턴에 대해 거름막 역할을 해주는 기능이다. 가장 중요한 것은 서블릿을 투과한 후 Filter를 거치고 그 이후에 스프링 영역(DispatcherServlet)에 접근하게 된다. 주요 사용하는 용도로는 인코딩, XSS, CORS 등에 관한 설정을 주로 한다. 이전 Spring에서는 web.xml에서 Java파일을 Filter를 추가하여 사용 할 수 있었는데, SpringBoot에서는 Annotation을 사용하여 Filter를 추가 할 수있다. 먼저 사용할 CustomerFilter를 Servlet이 제공하는 Filter인터페이스를 구현하여 만든다. 이때, chain.doFilter(request,response);를 해주지 않으면 다음 필터를 넘어가지 않게 되니 주의해서 ..
-
Oracle JDK 8 - > OPEN JDK 11 변경시 java -version 바꾸기JAVA공부/JAVA 2022. 6. 25. 15:47
1. 환경 변수 설정에서 기존에 JAVA_HOME -> jdk1.8.0.271 에서 jdk-11.0.2로 변경 2. path 환경 변수 편집창을 열어서 %JAVA_HOME%\bin 으로 설정 되어있는지 확인, 3. 마찬가지로 path 환경변수에서 C:\Program Files (x86)\Common Files\Java\java_path 가 있는지 확인 후 삭제 또한 해당 폴더에 직접 접근하여 모두 삭제해주어야한다. 4. 결과
-
테스트코드 BeforeEach를 통해 입력시 ID값이 초기화 되지 않을때SPRING 공부/JPA 2022. 6. 25. 01:51
@BeforeEach를 통해 매번 해당 데이터를 입력시킨 후 (이때 ID는 AutoIncrement되는 값) 이를 ID값으로 찾아오는 메서드를 사용하여 수정 / 삭제를 하려고 할때 , ID를 통해 데이터를 찾아오지 못했는데, 알고보니 BeforeEach를 수행할 때마다 AI값이 1씩 상승하게 되여 3번,4번 등으로 바뀌게 되었다. 따라서 EntityManager를 주입받아 AI값을 BeforeEach에 매번 초기화하는 메서드를 작성해줘야한다. 해당 쿼리는 DB종류마다 다다르게 작성되니 쿼리문을 찾아서 집어넣으면 해결된다.
-
JPA를 이용한 연관관계 입력 후 조인 쿼리조회시 안되는 문제SPRING 공부/JPA 2022. 6. 25. 01:45
Test 코드에서 Test Data를 BeforeEach에 넣어 두었는데. 나는 saveAndFlush를 하면 해당 쿼리 이후로 DB에 반영되어 조회가 되는 줄 알았다. 그러나 Controller로 해당 내용을 호출시 user에 대한 Entity는 조회가 되었으나, @OneToMany로 되어있는 pointHistory 리스트를 가져오지 못했다. 찾다가 찾다 해메서 EntityManager를 주입받아 clear()를 해주어야지만 영속성 컨텍스트가 비워지면서 조인쿼리로 해당 리스트들을 조회받을 수 있었다.
-
Spring Boot - Rest Api 파일 업로드토이프로젝트/하다사 2022. 6. 2. 20:43
1. 파일 업로드 AttachDTO(그룹ID) 객체로 AttachFileDTO(실제 파일) 목록을 받아와서 File 객체를 생성하여 서버 저장공간에 하나 씩 저장하면서 서버의 파일정보가 담긴 AttachDetailEntity를 생성해준다. 모든 AttachFileDTO목록이 끝나면 DB에 AttachEntity 의 정보를 JPA를 통해 입력시켜준다. 2. 파일 조회 조회 시에는 JPA Find 를 통해 Attach정보를 찾아와서 AttachEntity 객체를 생성해준다. AttachEntity에는 1:N의 AttachDetailList가 있기 때문에 같이 조회해온다. 프론트에서는 이 데이터를 받아서 서버 파일 경로와 파일 이름등을 맵핑시켜 데이터를 출력해준다. 3. 파일 삭제 파일을 제거하기 위해 DB에..