zoukankan      html  css  js  c++  java
  • SPRING IN ACTION 第4版笔记-第二章WIRING BEANS-008-在XML配置文件中引入JAVA配置文件 <import> 、<bean>

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

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

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

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

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

    1 <?xml version="1.0" encoding="UTF-8"?>
    2 <beans xmlns="http://www.springframework.org/schema/beans"
    3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4 xmlns:c="http://www.springframework.org/schema/c"
    5 xsi:schemaLocation="http://www.springframework.org/schema/beans
    6 http://www.springframework.org/schema/beans/spring-beans.xsd">
    7 <bean class="soundsystem.CDConfig" />
    8 <import resource="cdplayer-config.xml" />
    9 </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 )

  • 相关阅读:
    Topshelf 搭建 Windows 服务
    Xamarin.Android 6.0以后开启权限方法
    使用ADB安装apk安装包
    C# 杀掉系统中的进程
    C# 使用CefSharp嵌入网站
    .Net Core 基于 SnmpSharpNet 开发
    C#实现ActiveMQ消息队列
    ActiveMQ 安装方法
    C# FluentFTP类上传下载文件
    .NET Core 之 Nancy 基本使用
  • 原文地址:https://www.cnblogs.com/shamgod/p/5234937.html
Copyright © 2011-2022 走看看