티스토리 뷰
강사 : 서정우 강사님 (cafe : cafe.naver.com/kostaspring)
http://www.eclipse.org // eclipse 설치
수업 진행 방향
java SE -> JDBC -> servlet/jsp(model2) -> Ajax,JQuery -> Framework (EE계열) + (*)tiles
-----------------
java SE -> JDBC -> Android, Hybrid app(통계), Jquery Mobile (ME계열)
Spring DI(IoC)-제어의 역행(2일) -> AOP(2일) -> ibatis(1일) -> spring MVC(5일) + Ajax, Tiles
처음에 XML 후에 anotation으로 리뉴얼할 예정
주요 개념
-의존성 주입(Dependency Injection)
-관점 지향 프로그래밍(Aspect-Oriented Programming)
**spring lesson ** 목차
DI -> AOP -> DI AOP Annotation -> ibatis framework -> spring mvc -> ajax -> tiles
개발 방법
DL (Dependency Lookup) - ex)Connection pool
DI (Dependency injection) -객체 주입 방식 (new를 해서 생성하지 않음) - 결합도 낮아짐(유지보수 편리)
View |
Controller | Model |
html |
Servlet |
비즈니스 - Service |
view + controller = struts 1,2
controller + Model = spring
DI 설명
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 |
package test;
import model.Car;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestDI {
/**
* Spring DI : 계층간의 결합도를 낮추기 위해 설계시 적용
* -> 유지보수성 및 테스트 용이성
* how? spring Container 에서 객체 생성하여
* 사용하는 클라이언트 프로그램측은 추상화된 인터페이스 타입으로
* 주입받아 사용
* -> 구체적인 객체의 변화가 있더라도 인터페이스의 변화가 없으면
* 코드 수정이 필요없다.
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//Car car = new SportsCar();
// Car car = new Truck();
// car.go();
// DI로 변경
//spring config xml 을 로딩
ApplicationContext context = new ClassPathXmlApplicationContext("di.xml");
//spring container가 객체를 생성하여 반환한다.
Car car = (Car)context.getBean("car");
car.go();
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 |
package model;
public interface Car {
public void go();
}
package model;
public class SportsCar implements Car{
public void go(){
System.out.println("SportsCar go");
}
}
package model;
public class Truck implements Car{
public void go(){
System.out.println("truck go");
}
}
|
1
2
3
4
5
6
7
8
9 |
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="car" class="model.Truck"/>
</beans>
|
OO (Object - Oriented)
why? 보안
Encapsalation
"public interface, private implementation" 인터페이스는 보이고, 완성(실행)은 숨긴다.
Object
Component Object가 모인것
FrameWork : 반 완전한 app (Components + pattern)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 |
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 생성자를 통한 주입 연습 -->
<bean id = "car" class="model.Car">
<constructor-arg>
<value>k7</value>
</constructor-arg>
</bean>
<bean id = "friend" class="model.Friend">
<constructor-arg>
<value>Yoon</value>
</constructor-arg>
<constructor-arg>
<value>27</value>
</constructor-arg>
</bean>
<bean id = "owner" class="model.Owner">
<constructor-arg>
<value>Yoon</value>
</constructor-arg>
<constructor-arg>
<ref bean="car"/>
</constructor-arg>
</bean>
</beans> |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 |
package model;
public class Car {
private String model;
public Car(String model) {
super();
this.model = model;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
@Override
public String toString() {
return "Car [model=" + model + "]";
}
}
package model;
public class Friend {
private String name;
private int age;
public Friend(String name, int age) {
super();
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Friend [name=" + name + ", age=" + age + "]";
}
}
package model;
public class Owner {
private String name;
private Car car;
public Owner(String name, Car car) {
super();
this.name = name;
this.car = car;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Car getCar() {
return car;
}
public void setCar(Car car) {
this.car = car;
}
@Override
public String toString() {
return "Owner [name=" + name + ", car=" + car + "]";
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 |
package test;
import model.Car;
import model.Friend;
import model.Owner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestDI {
/**
* 생성자를 통한 injection 연습 예제
*/
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"di.xml");
Car car = (Car)context.getBean("car");
System.out.println(car.toString());
System.out.println("===================================");
Friend friend = (Friend)context.getBean("friend");
System.out.println(friend.toString());
System.out.println("===================================");
Owner owner = (Owner)context.getBean("owner");
System.out.println(owner.toString());
}
}
|
Car [model=k7]
===================================
Friend [name=Yoon, age=27]
===================================
Owner [name=Yoon, car=Car [model=k7]]
1일차
spring di 환경설정 -> log4j
spring library, eclipes에서 spring plug in 설치
DI(의존관계 주입) 개념 : IOC(제어의 역행)
결합도를 낮춘다 -> spring container에서 객체를 주입
2일차
OOP Key concept
Encapsulation, Inheritance, Polymorphism
DI -> 생성자 및 setter method를 이용한 주입
Log4j
AOP
'Framework > Spring' 카테고리의 다른 글
[Spring & ibatis] 수업 3일 (0) | 2013.04.24 |
---|---|
[Spring & ibatis] 수업 2일 (0) | 2013.04.23 |
[Spring]Spring3.0 MVC에서 폼(Form) 다루기 (0) | 2012.10.08 |
[Spring]Spring3.0 MVC로 Hello world 어플리케이션 만들기 (0) | 2012.10.08 |
[Spring]Spring3 MVC Framework 소개 (0) | 2012.10.08 |