package com.industry.
app;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
interface Machine {
void operate();
}
class LatheMachine implements Machine {
public void operate() {
System.out.println("Operating Lathe Machine...");
}
}
class MillingMachine implements Machine {
public void operate() {
System.out.println("Operating Milling Machine...");
}
}
class Workshop {
private Machine machine;
public void setMachine(Machine machine) {
this.machine = machine;
}
public void startWork() {
machine.operate();
}
}
public class IndustryApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Workshop workshop = (Workshop) context.getBean("workshop");
workshop.startWork();
}
}
<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="latheMachine" class="com.industry.app.LatheMachine"/>
<bean id="millingMachine" class="com.industry.app.MillingMachine"/>
<bean id="workshop" class="com.industry.app.Workshop">
<property name="machine" ref="latheMachine"/>
</bean>
</beans>