一、在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. Redis与Memcached对比

    Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富,有字符串.链表.集合和有序集合.支持在服务器端计算集合的并,交和补集等.还支持多 ...

  2. .net+easyui--combobox

    一:预定义结构的 select 元素创建组合框(combobox)值固定写死 <select class="easyui-combobox" name="state ...

  3. ecshop在PHP 5.4以上版本各种错误问题处理

    在php5.4版本之后有很多的函数与功能进行丢弃与升级功能了,现在国内很多CMS都还未按php5.4标准来做了,下面我整理了一些在ecshop在PHP 5.4以上版本各种错误问题处理. 1.PHP 5 ...

  4. Optimal Logging

    by Anthony Vallone How long does it take to find the root cause of a failure in your system? Five mi ...

  5. SqlServer优化博客网址

    CareySon Sql Server MVP : http://www.cnblogs.com/CareySon/

  6. oracle 11g卸载方法

    在网上查看了很多卸载oracle11g的方法,但是感觉都太复杂了,没有使用,最后查看了很多资料,得到一种比较简单,而且能完全卸载的方法: 在根目录下运行c:\app\Administrator\pro ...

  7. phaser源码解析(三) Phaser.Utils类下isPlainObject方法

    /** * #这是一个对jQuery.isPlainObject(obj)稍加修改的方法. 一个 普通对象 obj.toString() => "[object Object]&quo ...

  8. js自执行函数表达式

    // 下面2个括弧()都会立即执行 (function () { /* code */ } ()); // 推荐使用这个(function () { /* code */ })(); // 但是这个也 ...

  9. bzoj1014:[JSOI2008]火星人prefix

    思路:插入.修改操作是splay的模型,然后询问的话就可以二分答案,然后再用splay去判,关键就在于怎么去判断. 可以用字符串hash,splay每个节点维护一个hash域,然后就可以定义一个进制去 ...

  10. 2016.08.06计算几何总结测试day1

    T1 bzoj1132[POI2008]TRO 还是太弱了....测试时看到这题直接懵逼,极角排序什么的根本想不起来,只会n^3暴力怎么破......不过竟然有84.....QAQ 正解是n^2log ...