Spring
-
N + 1 문제Spring/JPA 2023. 8. 6. 16:55
JPA는 테이블 간의 연관관계를 Mapping 해주는 ORM기술의 하나이다. JPA는 Java의 객체지향적 관점과 DB의 테이블 참조관계 사이의 불일치하는 부분을 해소하면서 원하는 데이터를 가지고 올 수 있게 해준다. Spring data jpa를 사용하면서 맞닥드릴 수 있는 N + 1 문제에 대해서 설명하고 해결 방법을 알아보자. Spring Data JPA JPA는 성능 최적화를 위해 지연로딩이라는 기술을 활용한다. 지연로딩이란, 관련이 있는 엔티티를 필요한 시점에 로딩하는 것을 말한다. 예를 들어 Member entity와 Team entity가 있다고 가정해보자. Team 에는 여러명의 Member가 소속될 수 있다면, Member와 Team Entity는 N : 1 관계가 된다. 기본적으로 @M..
-
InterceptorSpring/MVC2-Filter 와 Interceptor 2023. 6. 20. 17:51
개념 스프링 인터셉터도 서블릿 필터와 동일하게 사용자의 권한에 따른 흐름을 효과적으로 제어할 수 있는 기술이다. 서블릿 필터가 서블릿이 제공하는 기술이라면, 스프링 인터셉터는 말그대로 스프링 MVC가 제공하는 기술이다. 앞서 설명한 필터와 매우 유사한 점이 많은 기술이지만, 적용되는 순서와 범위, 사용법에서는 다소 차이가 있다. 스프링 인터셉터의 흐름 HTTP 요청 ▶ WAS ▶ 필터 ▶ 서블릿(DispatcherServlet) ▶ 스프링 인터셉터 ▶ 컨트롤러 필터와 스프링 인터셉터는 적용되는 위치가 근본적으로 다르다. DispatcherServlet 이후에 적용되는 스프링 인터셉터는 필터와는 다르게 더 많은 정보를 가지고 사용자의 권한에 따른 흐름을 제어할 수 있다. (앞으로 설명할 내용이다) 또한 스..
-
Bean ValidationSpring/MVC2-Validation 2023. 6. 20. 01:53
2023.06.19 - [Spring/MVC2-Validation] - Validation 이전글 참고 Validation 개념 내가 만든 웹페이지에 1. 반드시 필요한 데이터이므로 반드시 작성을 요구한다던지, 2. 입력데이터의 범위 값을 설정한다던지, 3. 데이터의 타입을 제대로 받도록 하는 작업 은 매우 필수적 hongs429-blog.tistory.com 개념 Bean Validation 은 어노테이션으로 검증로직을 매우 편리하게 적용할 수 있는 기술이다. 우리가 장왕하게 작성했던 if절들이 사실은 몇가지 규칙기반으로 쉽게 작성가능하다. 이런 것을 도와주는 것이 바로 bean Validation인데, 이는 특정한 구현체가 아니라 기술표준을 말한다. 즉, 검증 어노테이션과 여러 인터페이스의 모음이라는..
-
ValidationSpring/MVC2-Validation 2023. 6. 19. 23:22
개념 내가 만든 웹페이지에 1. 반드시 필요한 데이터이므로 반드시 작성을 요구한다던지, 2. 입력데이터의 범위 값을 설정한다던지, 3. 데이터의 타입을 제대로 받도록 하는 작업 은 매우 필수적이다. 또 위의 과정에서 사용자가 실수로 잘못된 데이터를 입력했다면, 무엇이 어떻게 잘못되었는지 알려주어야 하는데, 그냥 오류페이지를 띄운다면 매우 좋지 않은 서비스가 될 것이다. 우리의 컨트롤러의 기능 중 하나는, 들어온 HTTP 요청이 과연 올바른 요청인지를 판단해주는 것이다. 위에서 언급한 3가지 내용은 일종의 유효성 검사이다. 웹에 대해서 어느정도 했었다면, 유효성검사를 자바스크립트, 그러니까 Client side에서 처리를 해봤을 것이다. 클라이언트 단에서 무언가 데이터를 검증하고 처리하는 것은 한계가 존재..
-
요청 매핑Spring/MVC1-스프링MVC 기본기능편 2023. 6. 17. 07:51
개요 클라이언트에서 서버로 데이터가 전달되는 방법은 크게 3가지로 나눌 수 있다. GET - 쿼리 파라미터 예시 : search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=0&ie=utf8&query=축구 메세지 바디 없이, URL에 데이터를 포함해서 전달하는 방식 검색, 필터, 페이징기능 에서 많이 사용하는 방식 POST - HTML Form 데이터 쿼리 파라미터와 비슷하지만, 이는 메세지 바디에 쿼리파라미터 형식으로 데이터를 전달한다 content-type : application/x-www-form-urlencoded 회원가입 처럼 post방식의 form태그에 정보를 직접 드러내지 않고 보낼 때 사용한다 HTTP message body 에 데이터를..
-
로깅Spring/MVC1-스프링MVC 기본기능편 2023. 6. 14. 10:27
개념 보통 어플리케이션을 개발하면서 다양한 로그를 남기는데, 우리가 흔히 알고 있는 System.out.println()의 경우, 필요하지 않는 경우네도 정보를 출력하게 된다. 이는 대용량 서비스시에 서버의 장애를 낳을 수 있는 요인이 될 수 있다. 하지만 서버를 가동하면서 필요한 정보를 남기는 logging은 반드시 필요하기 때문에, 각각의 개발환경에 맞는 log 레벨을 지정해주고 이를 관리할 필요가 있다. 스프링 부트의 로깅 라이브러리 스프링부트는 다음의 로깅 라이브러리를 기본으로 제공한다. SLF4J - http://www.slf4j.org Logback - http://logback.qos.ch SLF4J Simple Logging Facade for Java (SLF4J) The Simple L..
-
뷰리졸버(ViewResolver)Spring/MVC1-스프링MVC 구조이해 2023. 6. 14. 09:57
개념 뷰리졸버는 스프링MVC구조에서 FrontController 역할을 하는 DispatcherServlet이 우리가 원하는 View로 forwarding할 수 있게 도와주는 기능을 담당한다. 개발자는 보통 논리 경로를 작성하여 DispatcherServlet으로 넘겨주게 되는데, 이후 뷰리졸버에 의해 논리경로가 물리적 경로로 변경되게 되어있다. 뷰리졸버 물리적 경로 설정 방식 보통 현재의 MVC 패턴의 @Controller는 @RequestMapping( 현재 HandlerMapping + HandlerAdapterMapping 방식)에서 리턴값을 view의 논리경로를 반환한다. 이후 DispatcherServlet(프론트 컨트롤러)에서 ViewResolver에 의해 물리적 경로로 변경되게 되는데, 이..
-
핸들러 매핑과 핸들러 어댑터Spring/MVC1-스프링MVC 구조이해 2023. 6. 14. 09:41
개념 스프링 mvc 패턴이 기본적을 동작하는 원리는 다음과 같다. 1. url을 통해 어떤 핸들러를 사용할지 매핑한다. 2. 해당 핸들러를 이용할 수 있도록 핸들러 어탭터를 조회(support 메서드)하고 어탭터를 매핑한다. 3. 매핑된 어댑터를 통해 Controller의 기능을 실행하고 ModelAndView 객체를 리턴한다. 4. ViewResolver를 통해 논리경로에서 물리경로로 경로를 설정한다. 5. view를 rendering하여 client에게 보내준다. 여기서 우리는 핸들러 매핑과정과 핸들러 어댑터 과정을 살펴보자 HandlerMapping 1순위 - RequestMappingHandlerMapping : 어노테이션 기반의 컨트롤러인 @RequestMapping에서 사용 2순위 - Bean..