package sam06;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Ex06 {
public static void main(String[] args) {
VehicleImpl vc = new VehicleImpl("조형택");
vc.setRider("하하");
vc.setSpeed(50);
vc.ride();
ApplicationContext ac = new ClassPathXmlApplicationContext("bean06.xml");
Vehicle vh = (Vehicle) ac.getBean("vh6");
vh.ride();
}
}
package sam06;
public class VehicleImpl implements Vehicle {
private String name;
private String rider;
private int speed;
//생성자
public VehicleImpl(String name){
this.name = name;
}
// setter
public void setRider(String rider) {
this.rider = rider;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public void ride() {
System.out.println(name + " 님은(는) " + rider + "를 이용 " + speed + "km 속도로 탄다.");
}
}
<?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="vh6" class="sam06.VehicleImpl">
<constructor-arg value="곽승현"></constructor-arg>
<property name="rider" value="오토"></property>
<property name="speed"><value>300</value></property>
</bean>
</beans>
조형택 님은(는) 하하를 이용 50km 속도로 탄다.
곽승현 님은(는) 오토를 이용 300km 속도로 탄다.