[스프링프레임워크3.X IoC 강좌3]Spring IoC, 스프링 IoC, 스프링제어역행, Spring Framework3.2 Inversion Of Control
“오라클자바커뮤니티몰” 운영 시나리오 - 전략수정
나는 사업이 잘 안되었고 현대자동차도 매우 조건이 안 좋아서 대우자동차로 메이커를 변경하기로 했다.
1. DaewooMaker.java 클래스 생성
package edu.biz.ioc;
public class DaewooMaker implements CarMaker {
public DaewooMaker () {
}//:
}//:
public Car sell(Money money) {
System.out.println("I sold a car.");
Car car = new Car(“Tosca”);
return car;
}
}///~
System.out.println("I sold a car.");
Car car = new Car(“Tosca”);
return car;
}
}///~
2. OrderManager 클래스 수정
package edu.biz.ioc;
public class OrderManager {
private CarMaker maker;
private CarMaker maker;
public OrderManager(String name) {
this.maker = new DaewooMaker();
}
this.maker = new DaewooMaker();
}
public void order() {
Car car = this.maker.sell(new Money(1000));
}
Car car = this.maker.sell(new Money(1000));
}
}///~
3. OraderManager를 다음과 같이 수정
public class OrderManager {
private String name;
private CarMaker carMaker;
public OrderManager() {
}
public void order() {
Car car = this.carMaker.sell(new Money(1000));
}
//setter 메소드를 통해 CarMaker를 주입 받는다.
public void setCarMaker(CarMaker carMaker) {
this.carMaker = carMaker;
}
}///~
4. ioc.xml
<beans>
<bean id="hyundaiMaker" class=" edu.biz.ioc.HyundaiMaker"/>
<bean id=“daewooMaker" class=" edu.biz.ioc.daewooMaker"/>
<bean id="orderManager"
class=" edu.biz.ioc.OrderManager">
<property name="carMaker">
<ref bean="hyundaiMaker"/> <!– 이부분을 교체하면 소스코드 수정없이
CarMaker를 교체 가능!! à
</property>
</bean>
</beans>
5. orderManagerApp.java
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.xml.*;
import org.springframework.core.io.*;
public class OrderManagerApp {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BeanFactory factory =
new XmlBeanFactory(new FileSystemResource("WEB-INF/ioc.xml"));
OrderManager manager =
(OrderManager)factory.getBean("orderManager");
manager.order();
}
}
[100%환급,실무전문]빅데이터/SQL/자바/스프링/안드로이드/닷넷C… | 12-27 | 2695 | ||
[채용확정무료교육]오라클자바개발잘하는신입뽑기2개월과정,교육… | 12-11 | 1950 | ||
53 | [평일100%환급7건]Spring,자바&JSP,안드로이드,웹퍼블리싱,C#닷… | 03-15 | 1772 | |
52 | [주말]C#,ASP.NET마스터 | 01-31 | 1919 | |
51 | [기업100%환급,평일주간]SQL기초에서스키마오브젝트,PLSQL,힌트… | 01-31 | 2801 | |
50 | [주말주간]자바&웹,jQUERY,스프링프레임워크,마이바티스 | 01-31 | 1477 | |
49 | [평일주간,평일야간,주말]Spring,MyBatis,Hibernate개발자과정-… | 01-19 | 1811 | |
48 | [평일야간,주말]안드로이드개발자과정(Android기초실무) | 01-11 | 1688 | |
47 | [평일야간,주말주간야간]JAVA,Network&JSP&Spring,MyBatis,Hiber… | 01-03 | 2230 | |
46 | [100%환급,실무전문]빅데이터/SQL/자바/스프링/안드로이드/닷넷C… | 12-27 | 2695 | |
45 | [평일주간]NoSQL,MongoDB,빅데이터기초과정 | 12-19 | 1911 | |
44 | [평일주간야간, 주말]웹퍼블리싱 마스터(HTML5,CSS3,jQUERY,AJAX… | 12-14 | 1889 | |
43 | [채용확정무료교육]오라클자바개발잘하는신입뽑기2개월과정,교육… | 12-11 | 1950 | |
42 | [평일주간]빅데이터하둡기초과정(BigData Hadoop) | 12-09 | 1536 | |
41 | [평일야간]닷넷(C#,Network,ADO.NET,ASP.NET)마스터 | 12-01 | 1759 | |
40 | [기업100%환급]오라클&자바웹스프링신입과정3주(SQL,JAVA,JSP,Se… | 12-01 | 1963 | |
39 | [평일야간,주말]SQL기초에서실무까지(SQL기초,PLSQL,힌트,튜닝) | 12-01 | 1405 |
댓글 없음:
댓글 쓰기