一、在xml中引入xml,用<import>

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
www.it-ebooks.info
62 C HAPTER 2 Wiring beans
<import resource="cd-config.xml" />
<bean id="cdPlayer"
class="soundsystem.CDPlayer"
c:cd-ref="compactDisc" />
</beans>

二、在xml中引入java配置,用<bean>

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="soundsystem.CDConfig" />
<bean id="cdPlayer"
class="soundsystem.CDPlayer"
c:cd-ref="compactDisc" />
</beans>

或新建一个文件,引入所有配置文件,不管是xml还是java

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="soundsystem.CDConfig" />
<import resource="cdplayer-config.xml" />
</beans>

Whether I’m using JavaConfig or XML wiring, I often create a root configuration, as I’ve
shown here, that brings together two or more wiring classes and/or XML files. It’s in
this root configuration that I’ll also usually turn on component scanning (with either
<context:component-scan> or @ComponentScan )

SPRING IN ACTION 第4版笔记-第二章WIRING BEANS-008-在XML配置文件中引入JAVA配置文件 <import> 、<bean>的更多相关文章

  1. SPRING IN ACTION 第4版笔记-第二章WIRING BEANS-008-在Java配置文件中引入xml配置文件@Import、@ImportResource

    1. package soundsystem; import org.springframework.beans.factory.annotation.Autowired; public class ...

  2. SPRING IN ACTION 第4版笔记-第二章WIRING BEANS-006-当构造函数有集合时的注入

    一.当构造函数有集合时,只能用<CONSTRUCTOR-ARG>,不能用C-NAMESPACE 二. 1. package soundsystem.collections; import ...

  3. SPRING IN ACTION 第4版笔记-第二章WIRING BEANS-007-以set方法注入<property>\p-namespace\util-space

    一.注入简单属性 package soundsystem.properties; import org.springframework.beans.factory.annotation.Autowir ...

  4. SPRING IN ACTION 第4版笔记-第二章Wiring Beans-005-<constructor-arg>和c-namespace

    1. package soundsystem; public class SgtPeppers implements CompactDisc { private String title = &quo ...

  5. SPRING IN ACTION 第4版笔记-第二章-004-Bean是否单例

    spring的bean默认是单例,加载容器是会被化,spring会拦截其他再次请求bean的操作,返回spring已经创建好的bean. It appears that the CompactDisc ...

  6. SPRING IN ACTION 第4版笔记-第二章-003-以Java形式注入Bean、@Bean的用法

    1. package soundsystem; import org.springframework.context.annotation.Bean; import org.springframewo ...

  7. SPRING IN ACTION 第4版笔记-第二章-002-@ComponentScan、@Autowired的用法

    一.@ComponentScan 1. @Configuration //说明此类是配置文件 @ComponentScan //开启扫描,会扫描当前类的包及其子包 public class CDPla ...

  8. SPRING IN ACTION 第4版笔记-第二章-001-用@Autowired\@ComponentScan、@Configuration、@Component实现自动装载bean

    1. package soundsystem; import org.springframework.context.annotation.ComponentScan; import org.spri ...

  9. SPRING IN ACTION 第4版笔记-第一章-003-AOP介绍

    一.目标 要在BraveKnight调用embarkOnQuest()前后各做一些处理(调用Minstrel的方法) 二. 1.minstrel.xml <?xml version=" ...

随机推荐

  1. JavaScript平常会跳的坑系列(一)

    function Foo() { //定义foo函数 getName = function () { console.log('1');}; console.log(this); return thi ...

  2. asp.net 开发问题:Web 服务器上的请求筛选被配置为拒绝该请求,因为内容长度超过配置的值。

    "Web 服务器上的请求筛选被配置为拒绝该请求,因为内容长度超过配置的值." 这个问题在开发需要上传文件的时候可能会遇到,今天遇到这个问题,百度过也有挺多的修改方法. 方法1: 修 ...

  3. (转)ASP.NET禁用刷新重复提交Backspace键

    在网页制作中,由于Backspace键可以回退到上一个网页,利用了缓存的数据,从而导致一些错误发生.浏览器的后退按钮使得我们能够方便地返回以前访问过的页面,它无疑非常有用.但有时候我们不得不关闭这个功 ...

  4. Ajax.Utility.RegisterTypeForAjax(typeof(_Default)) 的使用

    语句的作用:页面注册方法的作用. Ajax.Utility.RegisterTypeForAjax(typeof(命名空间.类名)); 首先要在配置文件里配置 <httpHandlers> ...

  5. nginx上搭建HLS流媒体服务器

    http://blog.csdn.net/cjsafty/article/details/7922849 简介:HTTP Live Streaming(缩写是 HLS)是一个由苹果公司提出的基于HTT ...

  6. hadoop_集群安装_2

    由于上一篇文章http://www.cnblogs.com/inuyasha1027/p/hadoop_cluster_install_1.html 截图太多,占用了太多的地方,所以将VMTools ...

  7. javascript GB2312转UTF8

    /* * GB2312转UTF8 * 例: * var xx=new GB2312UTF8(); * var Utf8=xx.Gb2312ToUtf8("你aaa好aaaaa"); ...

  8. window环境下 node.js 游戏框架pomelo 安装与启动

    一.软件准备 1.1 下载node.js 1.2 下载python 2.5 < version <3.0 1.3 下载c++编译器(一般控制面板中-->程序和功能上已有,如果没有需要 ...

  9. 对REST的一些理解

    昨天学习REST,发现有篇文章写的真心不错,看了一遍,并没有完全理解,将一些感觉比较重要的做个记录.  文章链接:REST简介 定义 Representational State Transfer ( ...

  10. C++中string类型对象和double型变量之间的互相转换

    //convert string type value to double type value string s = "23"; double d; istringstream ...