一、前言

本文承接上一节:Spring_总结_03_装配Bean(三)之XML配置

在典型的Spring应用中,我们可能会同时使用自动化和显示配置。同时,可能在某些场景下我们需要混合使用JavaConfig和xml配置。

二、在JavaConfig中引用XML配置

(1)可使用 @import注解导入JavaConfig

假设我们的配置类已经很笨重了,这时,我们可以将配置进行拆分。用一个高级别配置来组合其他配置。

如:现在又两个配置类:CDConfig、CDPlayerConfig  以及一个高级配置SoundSystemConfig

@Configuration
@Import({CDPlayerConfig.class, CDConfig.class})
public class SoundSystemConfig {
}

若想将CDconfig用xml形式配置,则引入的时候需要使用

@Configuration
@Import(CDPlayerConfig.class)
@ImportResource("classpath:cd-config.xml")
public class SoundSystemConfig {
}

三、在XML中引用JavaConfig

在一个高级别XML配置中同时引入JavaConfig和XMLConfig

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/plugin"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/plugin http://www.springframework.org/schema/plugin/spring-plugin.xsd"> <!-- 1.通过 bean 引入JavaConfig -->
<bean class="soundsystem.CDConfig" /> <!-- 2.通过 import 引入其他xml配置 -->
<import resource="cdplayer-config.xml" /> </beans>

最新文章

  1. iOS网络编程
  2. NodeJS 模块开发及发布详解
  3. C/C++学习链接
  4. Firefox about
  5. SQL SERVER提供了大量的WINDOWS和SQLSERVER专用的排序规则
  6. TYVJ1939 玉蟾宫
  7. CodeForces 300C --数论
  8. python自动开发之第十二天
  9. BZOJ 1008 越狱
  10. solr源码导入eclipse
  11. JS之DOM那些事
  12. ESXI的安装和部署
  13. docker~docker-compose的使用
  14. bzoj 3697
  15. springBoot多数据源(不同类型数据库)项目
  16. mybatis 映射生成mapper和pojo ---逆向工程的使用过程
  17. HTML 页面meta标签
  18. C#取整函数Math.Round、Math.Ceiling和Math.Floor 【非原创,用来收藏,分享】
  19. 【多视图几何】TUM 课程 第3章 透视投影
  20. ajax 的前进 后退 问题 jquery.history

热门文章

  1. Oracle学习笔记—数据字典和常用命令(转载)
  2. Spring学习笔记4—流程(Spring Web Flow)
  3. ALE和IDocs
  4. 201703 ABAP面试题002
  5. public,protected,privat区别
  6. window端口号被占用解决
  7. php数组函数-array_rand()
  8. 第四篇、linux系统文件属性三
  9. POJ 2431 贪心+优先队列
  10. Oracle给不同组数据添加顺序