60
2시간 만에 시작하는 스프링 프레임워크 3.x 허광남 [email protected]

okspring3x

  • Upload
    kenu-heo

  • View
    18.693

  • Download
    3

Embed Size (px)

DESCRIPTION

2시간 만에 시작하는 스프링 프레임워크 3.x

Citation preview

Page 1: okspring3x

2시간 만에 시작하는 스프링 프레임워크 3.x

허광남[email protected]

Page 2: okspring3x

토픽

• 스프링 프레임워크 개요

• 스프링 프레임워크로 시작하는 웹 개발

• Maven 빌드 도구의 이해

• 스프링 개발환경과 DB서버

• 스프링 모듈 소개

Page 3: okspring3x

스프링 프레임워크 개요

• JavaEE development without EJB

• 2004

• 로드 존슨

Page 4: okspring3x

프레임워크 기본 컨셉

• Inversion of Control / Dependency Injection

• Aspect Oriented Programming

• Portable Service Abstractions

Page 5: okspring3x

http://www.springframework.net/docs/1.3.0/reference/html/psa-intro.html

Page 6: okspring3x

Plain Object

• POJO; Plain Old Java Object

• not like Servlet

• extends javax.servlet.http.HttpServlet

Page 7: okspring3x

IoC / DI

• 사용할 객체를 외부에서 주입

• 생성자의 인자 또는 setter 메소스 이용

• Strategy Pattern

Page 8: okspring3x

IoC 장점

• 플러그인 만들기 좋음

• Interface 준수

• 테스트 객체로, 주입 객체 바꿔치기

Page 9: okspring3x

IoC/DI

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

Page 10: okspring3x

PSA

• 포터블 서비스 추상화

• 환경에 종속되지 않도록 유연한 추상 계층

Page 11: okspring3x

AOP

• 로깅, 트랜잭션과 같이 산재된 코드 모듈화

• Advice

• Pointcut

• 스프링 Advisor

Page 12: okspring3x

스프링 아키텍처

Page 13: okspring3x

J2EE����������� ������������������  architecture

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

Page 14: okspring3x

J2EE����������� ������������������  without����������� ������������������  EJB

http://jangsunjin.tistory.com/166

Page 15: okspring3x

스프링 아키텍처

Page 16: okspring3x

모듈과 특징• 코어 컨테이너:

Core, Beans, Context, Expression Language

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

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

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

• 테스트: JUnit과 TestNG

Page 17: okspring3x

핵심 효과Modularity

Productivity

Portability

Testability

POJO 심플, 명료, 모듈

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

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

유닛, 통합 테스트 쉽게

http://www.springsource.org/features

Page 18: okspring3x

More Projects

• Spring AMQP

• Spring for Android

• Spring Batch

• Spring Data

• Spring Framework

• Spring Gemfire

• Spring Integration

• Spring Mobile

• Spring .NET  

• Spring Roo

• Spring Security

• Spring Social

• Spring Web Flow

• Spring Web Services

Page 19: okspring3x

소스 아키텍처

Page 20: okspring3x

SpringFramework Layers

ref:����������� ������������������  http://www.javajigi.net/display/OSS/Spring_MVC_2

Dom

ain

Mod

el

User Interface (View)

Web (Controller)

Service

Persistence (DAO)

Page 21: okspring3x

Request����������� ������������������  LifeCycle

http://www.javajigi.net/pages/viewpage.action?pageId=19398699

Page 22: okspring3x

코드 네비게이션

1. URL����������� ������������������  mapping

2. Controller

3. Service

4. DAO

5. SQL

SearchFind SelectionOpen ResourceOpen DefinitionHierarchyBack

ctrl+Hctrl+Kctrl+shift+RF3ctrl+Talt+←

Page 23: okspring3x

개발 코드 구성

• Maven Style• src/main/java/

• /resources/

• /webapp/

• /test/java/

• /resources/

• target/ (.gitignore)

• pom.xml

Page 24: okspring3x

STS

• 입문할 때는 Spring Tools Suite 추천

• http://www.springsource.org/sts

• Maven, Git

Page 25: okspring3x

가져오기

• https://github.com/kenu/egov

• zip download

• File > Import... > zip

• Existing Projects > archive file

• Customized Local Environment

Page 26: okspring3x

Run Sample

• Project > Clean...

• Run as > Run on Server

Page 27: okspring3x

새 프로젝트

Page 28: okspring3x

Spring Template Project

Page 29: okspring3x

Template Selection

Spring MVC Project

Page 30: okspring3x

Template Download

Page 31: okspring3x

Project Settings

Page 32: okspring3x

프로젝트 구성

Page 33: okspring3x

utf-8

Page 34: okspring3x

utf-8

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

Page 35: okspring3x

버전

Page 36: okspring3x

버전

http://open.egovframe.go.kr/projects/information/filearchive/5265

Page 37: okspring3x

Maven 빌드 도구

Page 38: okspring3x

Java Compile 단점

• 패키지별로 따로 지정

• make 또는 compile.bat

• 클래스패스 설정 어려움

Page 39: okspring3x

ANT

• Another Neat Tool http://ant.apache.org

• build.xml

• project > targets > tasks

• properties ${base.dir}

Page 40: okspring3x

Maven 빌드 도구• Convention over Configuration

• ANT의 자유로운 빌드 설정과 차별

• Jar 의존성 관리

• 버전 명시, 프로젝트별 중복 jar 관리

• 플러그인 관리

• 이클립스, 톰캣, Jetty 등의 연계 플러그인

Page 41: okspring3x

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

Page 42: okspring3x

Quick Start #2 pom.xml

my-app|-- pom.xml`-- src |-- main | `-- java | `-- com | `-- mycompany | `-- app | `-- App.java `-- test `-- java `-- com `-- mycompany `-- app `-- AppTest.java

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging>

<name>Maven Quick Start Archetype</name> <url>http://maven.apache.org</url>

<dependencies>

<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> </dependencies></project>

Page 43: okspring3x

Build Project

•mvn package

•package is a phase

•페이즈는 연속적인 작업들

Page 44: okspring3x

mvn compile이면1. validate2. generate-sources3. process-sources4. generate-resources5. process-resources6. compile

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

Page 45: okspring3x

Maven goal

• archetype:generate

• archetype: is the plugin

• archetype:generate is a goal

• plugin은 goal 모음집

•예) eclipse:eclipse, tomcat:run

Page 46: okspring3x

Maven phases

• validate

• compile

• test

• package

• integration-test

• verify

• install

• deploy

• clean

• site

Page 47: okspring3x

target/

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

• Hello World!

Page 48: okspring3x

m2eclipse

• eclipse plugin

• little buggy

Page 49: okspring3x

Deployment Assembly

Page 50: okspring3x

Nexus

http://cwgkorea.net/zbxe/cwg_consensus/44551����������� ������������������  

Page 51: okspring3x

without

Intranet Internet

Dev����������� ������������������  A

Dev����������� ������������������  B

Central

Page 52: okspring3x

with

Intranet Internet

Dev����������� ������������������  A

Dev����������� ������������������  B

Nexus Central

Page 53: okspring3x

settings.xml

• ~/.m2/settings.xml <settings> <mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf>

<url>http://192.168.0.8:7070/nexus/content/groups/public</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles></settings>

Page 54: okspring3x

관련����������� ������������������  리소스

•자바지기����������� ������������������  위키

⁻http://www.javajigi.net/display/SFL/Home

•전자정부표준����������� ������������������  프레임워크

⁻http://www.egovframe.go.kr/cop/bbs/selectBoardList.do?menu=2&submenu=2&bbsId=BBSMSTR_000000000002

⁻http://open.egovframe.go.kr/egov/download.php

• Spring����������� ������������������  3����������� ������������������  Tutorial:����������� ������������������  Setting����������� ������������������  Up����������� ������������������  &����������� ������������������  Configuring����������� ������������������  The����������� ������������������  Environment����������� ������������������  By����������� ������������������  Jason����������� ������������������  Tee

⁻http://www.theserverside.com/tutorial/Spring-30-Tutorial-Setting-Up-Configuring-The-Environment

Page 55: okspring3x

jPetStore Sample

• git svn clone https://src.springframework.org/svn/spring-samples/jpetstore/trunk

Page 56: okspring3x

Toby Spring 3.1

• 2부는 제공된 코드와 함께

• 1부, 2부 CD는 동일

• https://github.com/kenu/tobyspring31

Page 57: okspring3x

EgovFrame

• http://www.egovframe.go.kr

• 실행환경(스프링 3.0.5 기반)

• egovframe 2.0, 2.5

• 개발 위키 추천

• 오픈커뮤니티 Q&A 활용

• http://open.egovframe.go.kr

Page 58: okspring3x

KSUG

• Korea Spring User Group

• http://www.ksug.org

• 구글그룹스 메일링 기반

• 개발 전문가들 눈팅

Page 59: okspring3x

Q&A

Page 60: okspring3x

감사합니다