2시간 만에 시작하는
스프링 프레임워크 3.x
        허광남
    kenu@okjsp.pe.kr
토픽

• 스프링 프레임워크 개요
• 스프링 프레임워크로 시작하는 웹 개발
• Maven 빌드 도구의 이해
• 스프링 개발환경과 DB서버
• 스프링 모듈 소개
스프링 프레임워크 개요

• JavaEE development without EJB
• 2004
• 로드 존슨
프레임워크 기본 컨셉

• Inversion of Control / Dependency
  Injection
• Aspect Oriented Programming
• Portable Service Abstractions
http://www.springframework.net/docs/1.3.0/reference/html/psa-intro.html
Plain Object

• POJO; Plain Old Java Object
• not like Servlet
• extends javax.servlet.http.HttpServlet
IoC / DI

• 사용할 객체를 외부에서 주입
• 생성자의 인자 또는 setter 메소스 이용
• Strategy Pattern
IoC 장점

• 플러그인 만들기 좋음
• Interface 준수
• 테스트 객체로, 주입 객체 바꿔치기
IoC/DI




egovframe 실행환경교재(01.공통기반).pdf 33p
PSA


• 포터블 서비스 추상화
• 환경에 종속되지 않도록 유연한 추상 계층
AOP

• 로깅, 트랜잭션과 같이 산재된 코드 모듈화
• Advice
• Pointcut
• 스프링 Advisor
스프링 아키텍처
J2EE
 architecture




                        http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Overview7.html
J2EE
 without
 EJB




                                                         http://jangsunjin.tistory.com/166
스프링 아키텍처
모듈과 특징
•   코어 컨테이너:
    Core, Beans, Context, Expression Language


•   데이터 접근/통합:
    JDBC, ORM, OXM, JMS, 트랜잭션 모듈


•   웹:
    웹, 웹-서블릿, 웹-스트러츠, 웹-포틀릿


•   AOP와 인스트루먼테이션:
    코드의 반복적인 중복을 일원화, 클래스로딩 제어


•   테스트:
    JUnit과 TestNG
핵심 효과
                      Modularity
                      POJO 심플, 명료, 모듈



                      Productivity
                      70% 개발자 보고, 시간 단축


                      Portability
                      톰캣, JavaEE, 클라우드 플랫폼


                      Testability
                      유닛, 통합 테스트 쉽게

http://www.springsource.org/features
More Projects
•   Spring AMQP          •   Spring Mobile

•   Spring for Android   •   Spring .NET  

•   Spring Batch         •   Spring Roo

•   Spring Data          •   Spring Security

•   Spring Framework     •   Spring Social

•   Spring Gemfire        •   Spring Web Flow

•   Spring Integration   •   Spring Web Services
소스 아키텍처
SpringFramework Layers
                  User Interface (View)
   Domain Model
                   Web (Controller)

                              Service

                   Persistence (DAO)
                      ref:
 http://www.javajigi.net/display/OSS/Spring_MVC_2
Request
 LifeCycle




            http://www.javajigi.net/pages/viewpage.action?pageId=19398699
코드 네비게이션

1. URL
 mapping
2. Controller
3. Service
                                                  Search           ctrl+H
4. DAO                                            Find Selection
                                                  Open Resource
                                                                   ctrl+K
                                                                   ctrl+shift+R
                                                  Open Definition   F3
5. SQL                                            Hierarchy        ctrl+T
                                                  Back             alt+←
개발 코드 구성
• Maven Style
 •   src/main/java/

 •             /resources/

 •             /webapp/

 •      /test/java/

 •             /resources/

 •   target/ (.gitignore)

 •   pom.xml
STS

• 입문할 때는 Spring Tools Suite 추천
• http://www.springsource.org/sts
• Maven, Git
가져오기

• https://github.com/kenu/egov
• zip download
• File  Import...  zip
• Existing Projects  archive file
• Customized Local Environment
Run Sample


• Project  Clean...
• Run as  Run on Server
새 프로젝트
Spring Template Project
Template Selection

          Spring MVC Project
Template Download
Project Settings
프로젝트 구성
utf-8
utf-8




프로젝트 전체 인코딩      이클립스 전체 인코딩
버전
버전




http://open.egovframe.go.kr/projects/information/filearchive/5265
Maven 빌드 도구
Java Compile 단점

• 패키지별로 따로 지정
• make 또는 compile.bat
• 클래스패스 설정 어려움
ANT

• Another Neat Tool http://ant.apache.org
• build.xml
• project  targets  tasks
• properties ${base.dir}
Maven 빌드 도구
• Convention over Configuration
 • ANT의 자유로운 빌드 설정과 차별
• Jar 의존성 관리
 • 버전 명시, 프로젝트별 중복 jar 관리
• 플러그인 관리
 • 이클립스, 톰캣, Jetty 등의 연계 플러그인
Quick Start

•mvn --version
•mvn archetype:generate
 -DgroupId=com.mycompany.app
  -DartifactId=my-app
  -DarchetypeArtifactId=maven-
  archetype-quickstart
  -DinteractiveMode=false


     http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
Quick Start #2
                     pom.xml
                                            project xmlns=http://maven.apache.org/POM/4.0.0
                                            xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
                                            xsi:schemaLocation=http://maven.apache.org/POM/4.0.0
    my-app                                  http://maven.apache.org/xsd/maven-4.0.0.xsd
                                              modelVersion4.0.0/modelVersion
|-- pom.xml
`-- src                                       groupIdcom.mycompany.app/groupId
    |-- main                                  artifactIdmy-app/artifactId
    |   `-- java                              version1.0-SNAPSHOT/version
    |        `-- com                          packagingjar/packaging
    |            `-- mycompany
                                              nameMaven Quick Start Archetype/name
    |                `-- app                  urlhttp://maven.apache.org/url
    |                    `-- App.java
    `-- test                                  dependencies
        `-- java                                 dependency
             `-- com                               groupIdjunit/groupId
                 `-- mycompany                     artifactIdjunit/artifactId
                     `-- app                       version4.8.2/version
                         `-- AppTest.java          scopetest/scope
                                                 /dependency
                                              /dependencies
                                            /project
Build Project

•mvn package
•package is a phase
•페이즈는 연속적인 작업들
mvn compile이면
1.   validate
2.   generate-sources
3.   process-sources
4.   generate-resources
5.   process-resources
6.   compile

•    compile 까지의 페이즈를 순서대로 수행
Maven goal

• archetype:generate
• archetype: is the plugin
• archetype:generate is a goal
• plugin은 goal 모음집
• 예) eclipse:eclipse, tomcat:run
Maven phases
• validate           • install
• compile            • deploy
• test
• package            • clean
• integration-test   • site
• verify
target/


• java -cp target/my-app-1.0-
  SNAPSHOT.jar com.mycompany.app.App

• Hello   World!
m2eclipse


• eclipse plugin
• little buggy
Deployment Assembly
Nexus




http://cwgkorea.net/zbxe/cwg_consensus/44551
 
without
                                         Intranet   Internet


Dev
 A

                                                    Central

Dev
 B

okspring3x