/////////////////////////////////////////////////////////////////////////////////////
"-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
"fooBean" class="AutoBean"/>
"barBean" class="AutoBean"/>
/////////////////////////////////////////////////////////////////////////////////////
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();
}
}
(出处:http://www.knowsky.com)