topgaren / DevStudy

0 stars 0 forks source link

Spring #1

Open topgaren opened 4 years ago

topgaren commented 4 years ago

Spring Framework Study

topgaren commented 4 years ago

Spring Basic

0. 스프링 프레임워크(Spring Framework) 개요

: 자바 엔터프라이즈 개발을 편하게 해주는 오픈소스 경량급 애플리케이션 컨테이너.

1. IoC(Inversion of Control)

일반적으로 객체를 생성하고 다른 객체와의 의존성을 만들기 위해선 프로그래머가 직접 객체를 생성하는 방식으로 진행되었다. 즉 객체를 제어하는 주체는 프로그래머였다. 그러나 스프링 컨테이너가 객체의 생성 및 소멸을 담당함으로써 객체에 대한 제어권은 프로그래머가 아니라 스프링 프레임워크로 넘어가게 되었다.

2. DI(Dependency Injection)

의존 관계가 생기는 상황은 다음과 같다. 클래스 B의 내부에서 클래스 A의 인스턴스를 생성하여 참조한다면, 클래스 B는 클래스 A에 대한 의존 관계가 생기게 된다. 그리고 위 처럼 new 키워드를 사용하여 내부적으로 객체를 생성하는 방식이 아니라 외부에서 객체를 생성하고 그 인스턴스를 넣어주는 것을 의존성 주입(Dependency Injection)이라고 표현한다.

3. AOP(Aspect-Oriented Programming)

스프링 프레임워크는 핵심 비즈니스 로직 구현에 집중할 수 있는 방법을 제공한다. 대부분의 시스템이 가지고 있는 보안, 로그, 트랜잭션 등 비즈니스 로직은 아니지만 반드시 처리해야하는 부분을 가리켜 스프링에서는 "횡단 관심사(Cross-Concern)"라고 한다. 스프링 프레임워크에서는 이러한 횡단 관심사를 모듈로 분리시킴으로써 반복적으로 나타나는 코드를 제거할 수 있게 한다.

Reference https://hoonmaro.tistory.com/32 https://limmmee.tistory.com/13?category=654011

topgaren commented 4 years ago

Spring MVC

1. MVC 패턴

위키백과 "모델-뷰-컨트롤러" 모델-뷰-컨트롤러(Model–View–Controller, MVC)는 소프트웨어 공학에서 사용되는 소프트웨어 디자인 패턴이다. 이 패턴을 성공적으로 사용하면, 사용자 인터페이스로부터 비즈니스 로직을 분리하여 애플리케이션의 시각적 요소나 그 이면에서 실행되는 비즈니스 로직을 서로 영향 없이 쉽게 고칠 수 있는 애플리케이션을 만들 수 있다.

image

2. Spring MVC

MVC 패턴에 따라 웹 애플리케이션을 제작할 수 있도록 스프링에서 제공하는 프레임워크.

image

Image 참고 : http://egloos.zum.com/springmvc/v/504151

2-1. Dispatcher Servlet과 View Resolver 설정

<!-- file: src/main/webapp/WEB-INF/web.xml -->
<!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
<!-- file: src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml -->
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

2-2. Spring MVC 프로젝트 구조

image

Image 출처 : https://gmlwjd9405.github.io/2018/12/20/spring-mvc-framework.html

Reference https://gmlwjd9405.github.io/2018/12/20/spring-mvc-framework.html https://jeong-pro.tistory.com/96