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 )

  • 相关阅读:
    图的深度遍历
    判断森林中有多少棵树
    基于邻接矩阵的广度优先搜索
    第三届程序设计知识竞赛网络赛
    大数相乘
    a+b=x,ab=y
    poj3278
    不敢死队
    单链表中重复元素删除
    poj2506
  • 原文地址:https://www.cnblogs.com/shamgod/p/5234937.html
Copyright © 2011-2022 走看看