스프링군살없이세팅하기(The way to setting the Spring framework for web.)
깔끔하게 스프링 프레임워크 세팅하는 것에 대한 이야기 입니다. 군살없이 프레임워크를 세팅한다는 의미와 이유, 그리고 스프링 기본 설정 및 설정들의 역할에 대해서 정리해 보았습니다. This presentation is about Spring framework. I want to talk about the way to setting the spring framework as tidy in this presentation.
0_(1/2) 강사소개 강 사: 신은철 경 력 : 개발경력 10년 2013.7 ~ KT 뮤직, 음원 메타 및 라이선스 관리 시스템 개발 및 유지보수 2007.8 ~ 2013.7 하늘연 소프트, 한국고용 정보원 워크넷 차세대 시스템 구축 외 13개 프로젝트 - 하늘연 재직 당시 다수의 공공 SI 프로젝트에 PL 로 참여하여 다양한 프레임워크를 경험함 (jsp, javaBeans, Spring, Struts, Spring + Struts, 전자정부프레임워크, Jgarnet, Spring 3.x) - KT 뮤직에서 담당하고 있는 시스템에 Spring 3.2, Spring 4.2등을 도입함.
3.
0_(2/2) 오늘 할이야기들.. 1. 군살없이 스프링을 세팅한다는 것은? 2. STS(Spring Tool Suite)로 스프링 프로젝트 생성하기 3. STS가 생성한 스프링 설정 살펴보기 4. DI를 이해하기 위한 Sample Code 작성하기
1_(1/3) 군살 없이스프링을 세팅한다는 것은? 필요한 것만 세팅 세팅된 모든 것을 알고 인지함
6.
1_(2/3) 스프링 프레임워크를세팅하는 방법들.. 1. Dynamic Web Project 생성 후 직접 스프링 세팅 2. STS (Spring Tool Suite) 이용하여 스프링 프로젝트 생성 3. 이전 프로그램에서 스프링 설정만 복붙 4. 이전 프로그램에서 비지니스 로직 삭제 (재활용성을 극대 화 하기 위해 공통소스는 남겨둠)
7.
1_(3/3) 왜 정확히알고 필요한 것만 세팅해야 할까? 속도 향상 예상 외의 오류 방지 기술의 대체가 가능
2_(1/3) 준비물.. ● EclipseJava EE IDE for Web Developers (MARS.2 release 4.5.2) ● JDK 1.8.0_91 ● Tomcat 8.0.36 (※ 8.0.35 버그 있음) ● Spring Tool Suite For Eclipse 3.8.0 RELEASE
10.
2_(2/3) 프로젝트 생성하기 프로젝트생성 : New → Other.. → Spring Legacy Project → Spring MVC Project 프로젝트 확인 : Tomcat add→ Tomcat port&context 확인 → Tomcat start → 확인
11.
2_(3/3) STS(Spring ToolSuite)로 스프링 프로젝트를 만들면? 엄청 간단한 생성방법 설정할 줄 몰라도 사용할 줄만 알면 개발이 가능 스프링 유저 코더? STS 가 사라 진다면? 아니 스프링 프레임워크가 사라진다면?
3_(2/10) ContextLoaderListener 설정코드 <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml</param-value> </context-param> <!-- Creates the Spring Container shared by all Servlets and Filters --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
3_(9/10) servlet-context.xml <annotation-driven /><!-- mvc 관련 annotation 처리 --> <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> <resources mapping="/resources/**" location="/resources/" /> <!-- 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> <context:component-scan base-package="com.softcamp.sample1" /> Dispatcher 에서 처리할 필요없는 Resource(img,css,js…) 영역을 설정함.. @Component 또는 @Component를 메타 어노테이션으로 갖고 있는 어 노테이션(@Controller, @Repository, @Service를 말함)이 붙은 클래스를 빈으로 등록 MVC annotation(RequestMapping, RequestBody, RequestParam.. 등)을 처리하는 Bean 들을 설정함.. 3.0이하에서는 예외 처리가 불가 3.1부터 예외 처리가 가능
22.
3_(10/10) ContextLoaderListener 과의DispatcherServlet 관계 ContextLoaderListener => Root WAC(WebApplicationContext) DispatcherServlet => Child WAC(WebApplicationContext) Child WAC => Root WAC 참조 (O) Root WAC => Child WAC 참조 (X) Root WAC : 웹에 종속적이지 않은 빈 ex) 서비스, DAO Child WAC : 웹에 종속적인 빈 ex) 컨트롤러, 스프링 MVC관련 빈