zoukankan      html  css  js  c++  java
  • Spring_总结_03_装配Bean(四)_导入与混合配置

    一、前言

    本文承接上一节: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>
  • 相关阅读:
    js-html音乐播放
    CSS-实现倒影效果box-reflect
    html-屏蔽按键盘空格键是滚动条向下滚动
    html-禁用右键、键盘F12、网页上选取内容、复制、粘贴
    js-回调函数
    man bash 关于shell的应有尽有 语法、快捷键...
    source vs export AND ctrl d vs ctrl z
    技术----阳春
    限流 降级
    linux TOP
  • 原文地址:https://www.cnblogs.com/shirui/p/9383332.html
Copyright © 2011-2022 走看看