一、在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. JQuery_AJAX简单笔记

    <script type="text/javascript"> //Ajax方法 $.ajax({ type: "post", cache: fal ...

  2. sqlserver2008中如何用右键可视化的设置外键

    右键->设计 然后打表设计界面打开了然后右键点你要设置与其它表关联的列然后点关系,选择外键表与列然后点保存,就这样  

  3. android开发者博客二月-Marshmallow and User Data

    又是一篇翻译,这篇快了很多,不过也花了快一个小时,可能熟悉一点.关于6.0权限的,让你做用户认为正确的事情. Marshmallow and UserData 2016,2,1 棉花糖和用户数据 由J ...

  4. UML类图细节

    类图表述的是类和类之间的关系,是前期用来推演代码设计,后期用来优化代码的结构,寻找设计不合理之处.网上解释类图和类图的画法,往往表述的十分晦涩,或者例子呆板,很难具体的操作. 类图一般在详细设计过程中 ...

  5. SQL Server 脚本语句

    一.语法结构 select select_list [ into new_table ] from table_source [ where search_condition ] [ group by ...

  6. 在office 2010中插入Mathtype出现ctrl+v不能复制的问题

    加载项中去掉command for那个即可 详细网址:http://heblue.blog.163.com/blog/static/96325568201375102628405/

  7. CSS3 transition-timing-function

    CSS3 transition-timing-function 属性 定义和用法 transition-timing-function 属性规定过渡效果的速度曲线. 该属性允许过渡效果随着时间来改变其 ...

  8. Less 官方文档学习笔记

    LESS 是css的一种扩展,它的编辑器是基于node.js 的less.js,将less文件编译成css文件(可压缩). 其中的概念: 变量:定义变量来代替某个值,只能编译一次,本质是“常量”.例如 ...

  9. java新手笔记17 参数

    package com.yfs.javase; public class ParamDemo { public static void main(String[] args) { int a = 3, ...

  10. 迭代map方法

    Map<String, String> map=new HashMap<String,String>();map.put("1", "one&qu ...