除了写很简单的加载一个xml,加载多个的情况一直没用到,在公司里也不会由自己处理这个问题,现在需要用到了,就研究验证一下。

  使用的案例还是上面的例子。

  只有,将原来的beans.xml分成两个部分。

  

1.结构

  

2.beans.xml

 <?xml version="1.0" encoding="UTF-8"?>
<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"> <!--
加载一个xml,这个作为总的xml入口
-->
<import resource="beans2.xml"/> <bean id="helloWorldService" class="com.it.bean.HelloWorldService">
<property name="helloWorld" ref="springHelloWorld"/>
</bean> </beans>

3.beans2.xml

 <?xml version="1.0" encoding="UTF-8"?>
<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="springHelloWorld" class="com.it.service.SpringHelloWorld"></bean> </beans>

4.运行类

 package com.it.main;

 import com.it.service.HelloWorld;
import com.it.bean.HelloWorldService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class HelloMain {
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); HelloWorldService service = (HelloWorldService) context.getBean("helloWorldService"); HelloWorld hw= service.getHelloWorld(); hw.sayHello();
}
}

  

最新文章

  1. ATM-PROGRAM 关于Proprties的问题
  2. ArcGIS Engine开发之地图浏览
  3. linux工作用到的
  4. HTML5触屏版多线程渲染模板技术分享
  5. 不挣扎了,开始学习LINQ TO XML,进而来解析网页。
  6. 如何判断C#的Finalizer线程有没有被阻塞
  7. android发送/接收Json包含中文的处理
  8. asp.net 服务器端缓存与客户端缓存 [转]
  9. ORACLE 日志 logminer 使用
  10. php对xml的处理
  11. win7 64位 Xsheel
  12. 【linux kernel】 中断处理-中断上半部
  13. 优秀的前端project如何制定一个老师--html学习路径
  14. Linux Centos7配置防火墙开启端口
  15. Python学习【第26篇】:Python系列- 多线程(threading)
  16. 【Django基本命令002】
  17. struts2之数据校验
  18. CentOS 6下升级Python版本
  19. [W3bsafe]分享一个爬SQL注入漏洞的工具
  20. Web开发中button与submit区别

热门文章

  1. Docker入门02——Dockerfile详解
  2. HashMap原理分析(JDK1.7.x之前)
  3. shiro授权及自定义realm授权(七)
  4. win10 + ubuntu双系统详细安装过程
  5. scp -r拷贝目录不会拷贝软连接
  6. Redis消息通知(任务队列和发布订阅模式)
  7. win32编程:L,_T() ,TEXT和_TEXT
  8. shell脚本中冒号
  9. zabbix3.0.4关于java服务端程序内存溢出的处理
  10. freeswitch用户整合(使用mysql数据库的用户表)