Bean Name Example
/* Pro Spring By Rob Harrop Jan Machacek ISBN: 1-59059-461-4 Publisher: Apress */ ///////////////////////////////////////////////////////////////////////////////////// <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="fooBean" class="AutoBean"/> <bean id="barBean" class="AutoBean"/> </beans> ///////////////////////////////////////////////////////////////////////////////////// public class AutoBean { public void foo() { System.out.println("foo()"); } } ///////////////////////////////////////////////////////////////////////////////////// import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; public class BeanNameExample { public static void main(String[] args) { ApplicationContext ctx = new FileSystemXmlApplicationContext( "build/bnapc.xml"); AutoBean fooBean = (AutoBean)ctx.getBean("fooBean"); AutoBean barBean = (AutoBean)ctx.getBean("barBean"); fooBean.foo(); barBean.foo(); } }