获得Spring Bean
2007-12-23 12:34:27 来源:WEB开发网核心提示:/"-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">"fooBean" class="AutoBean"/>"
/////////////////////////////////////////////////////////////////////////////////////
"-//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();
}
}
"-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
/////////////////////////////////////////////////////////////////////////////////////
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.cncms.com)
[]
更多精彩
赞助商链接