spring提供了初始化应用上下文环境的配置文件,此外在程序中可以通过ClassPathXmlApplicationContext或FileSystemXmlApplicationContext类实现个性化的配置导入。
1. ClassPathXmlApplicationContext
导入XML从CLASSPATH路径中寻找XML文件并导入.
比如:
ApplicationContext classpathCtx = new ClassPathXmlApplicationContext("helloWorld.xml");
HelloWorld helloBean = (HelloWorld) classpathCtx.getBean("helloWorld");
2.FileSystemXmlApplicationContext
从文件路径中导入配置文件,需要一个可访问的文件全路径
比如:
FileSystemXmlApplicationContext fileCtx = new FileSystemXmlApplicationContext("C:\\helloWorldFile.xml");
HelloWorld helloBean = (HelloWorld) fileCtx.getBean("helloWorld");
上一篇: Spring XML配置<list>注入Bean属性举例 2012-01-22 17:05
下一篇: Spring Inversion Of Control (IOC)依赖注入举例 2012-01-21 19:05
Copyright©2007-2012 www.txdnet.cn All Rights Servered. Powered By JITCMS V1.5 京ICP备09017503号.
Host By www.fjjsp.com
.