위 링크 블로그에 개념이 잘 설명되어 있다.
요약하면 소프트웨어 개발에서의 프레임워크란 필요한 것을 개발하기 위한 도구와 틀을 모아둔 세트이며
이 프레임워크 기반에서 개발함으로써 기반공사의 수고로움을 덜어주고 누가 개발을 해도 비슷한 스타일의 결과물이 나온다.
건축으로 보자면 기반공사가 끝났고 이제 이 위에 층을 올리면된다.
그 중에 Spring Framework는 웹 개발을 위한 프레임워크란다.
Figure 2.1. Overview of the Spring Framework
Understanding the flow of Spring Web MVC
http://www.javatpoint.com/spring-3-mvc-tutorial
https://gmlwjd9405.github.io/2018/11/05/mvc-architecture.html
(계속..)
Spring의 구성
1) IOC(Inversion of Control): 기존의 프로그래밍에서 객체의 생성, 제어, 소멸 등의 객체의 라이프 사이클을 개발자가 관리 하던 것을 컨테이너 에게 그 제어권을 위임. 즉, 의존성들을 외부(XML,properties) 에 정의하고 컨테이너에 의해 공급받는 프로그래밍 기법. 객체의 생성에서부터 생명주기의 관리까지 모든 객체에 대한 제어권이 바뀌었다는 것을 의미한다는 것이다.
2) AOP(Aspect Oriented Prog.): xxx
Aspect: 특정상황(point-cut)과 그 상황때 수행할 작업(advice)의 집합
● Loosely Coupled vs. Tightly Coupled
● POJO (Plan Old Java Object)
● DI(Depenency Injection, 의존관계 주입)
▽을 이용한 설정, 매핑 (DI: Depenency Injection)
1) XML
2) Annotation
● DI(Depenency Injection, 의존관계 주입) Example
// 탈것 Class & Interface // 파일경로: src/main/java/IVehicle.java public interface IVehicle { void ride(); } // 파일경로: src/main/java/IVehicle.java import java.util.ArrayList; public class VehicleImpl implements IVehicle { private String name; private String rider; private int speed; private ArrayList<string> parts; // 부품 목록 @Override public void ride() { System.out.println(name+"이 "+rider+"를 "+speed+"km 의 속도로 달린다."); } // Constructor public VehicleImpl(String name, String rider) { this.name = name; this.rider = rider; } // Setters public void setName(String name) { this.name = name; } public void setRider(String rider) { this.rider = rider; } public void setSpeed(int speed) { this.speed = speed; } public void setParts(ArrayList<string> parts) { this.parts= parts; } }
<!-- 파일경로: src/main/resources/bean05.xml <!--?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"> <!-- 방법1) Constructor Injection --> <bean id=" msgbean05" class="pkg.ClassName01"> <constructor-arg><value>첫번째값</value></constructor-arg> <constructor-arg value="두번째값"/> <!-- 방법2) Setter Injection(Property) --> <bean id="msgBean06" class="sam06_DI2.MessageBeanImpl"> <property name="name"><value>spring</value></property> <property name="greet" value="어서옵셔!"></property> </bean> <!-- 방법3) Method Injection --> <bean id="bean07" class="sam07.VehicleImpl"> <constructor-arg value="소형"> <!-- 생성자 이용/name이 없어도 되며 없으면 순서대로 매핑 --> <constructor-arg value="자전거"> <!-- 생성자 이용/name이 없어도 되며 없으면 순서대로 매핑 --> <property name="rider"><value>자전거</value></property> <!-- property는 setter --> <property name="speed" value="22"/> <property name="parts"> <!-- ArrayList 형 주입하기 --> <list> <value>바퀴</value> <value>안장</value> <value>체인</value> <value>핸들바</value> <value>프레임</value> </list> </property> </bean> </beans>
// 파일경로: src/main/java/Ex.java import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; public class Ex01 { public static void main(String[] args) { ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:/bean05.xml"); MessageBean mb = (MessageBean)ac.getBean("msgBean05"); // 위의 new한것과 같은 효과 mb.sayHello("spring"); // or String configLocation = "classpath:applicationCTX2.xml"; AbstractApplicationContext ctx = new GenericXmlApplicationContext(configLocation); MyInfo myInfo = ctx.getBean("myInfo", MyInfo.class); myInfo.bmiCalculation(); ctx.close(); } }● XML Bean 환경파일 생성 New > Spring Bean Configration File
'글' 카테고리의 다른 글
VI. MyBatis (0) | 2017.03.31 |
---|---|
jQuery Mobile 관련링크 (0) | 2012.03.26 |
이론 링크 모음 (알고리즘/형상관리) (0) | 2012.03.07 |
물리엔진 개념과 대표적인 엔진 (0) | 2012.03.06 |
Dropbox에 올리고 Public Link로 공유하기 (2) | 2012.03.05 |