<?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:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <!--  <context:component-scan base-package="com.chinasofti.bean"></context:component-scan>  -->  

    <!-- 构造器方式 -->
    <bean id="dog" class="day1.Dog">
        <!-- 有参的类: constructor-arg 标签代表有参构造,index对应第几个参数,value是值 -->
        <constructor-arg index="0" value="杀魔爷"></constructor-arg>
        <constructor-arg index="1" value="888"></constructor-arg>

    </bean>

    <!-- 静态工厂方式  -->
    <bean id="product" class="beans.staticFactorys" factory-method="getProduct"></bean>

    <!-- 非公共类 -->
    <bean id="div" class="beans.Div"></bean>

    <!-- 普通类的方法 返回的对象 -->
    <bean id="factory" class="beans.Factory" ></bean>
    <bean id="product2" factory-bean="factory" factory-method="getProduct"></bean>

        <!-- 导入其他的配置文件-->
         <import resource="ac.xml"/>
<!-- 默认情况下每个bean 的scope的值是 singleton 即 单例模式,该模式下容器只存在一个bean
        在单例模式下属性 lazy-init 可以决定bean的创建事件,默认:false 时随着IOC 容器的创建而创建
            (ApplicationContext ac=new ClassPathXmlApplicationContext("ac.xml");)
        该值为true 时 ,则第一场获取对象 (getBean()) 是创建对象

        scope 的值是 prototype 时 即 多例模式  其 lazy-init 的值就只能是 true 

        init-method: 初始化方法
        destory-method: 销毁方法
     -->
    <bean id="dog" class="day1.Dog" scope="singleton" init-method="setName" destroy-method="destory"/>

    <!-- property 标签 可以给初始化成员变量  -->

        <!-- 1.Boy boy=new Boy();
             2.boy.setName(小明)
               boy.setDog(new Dog());
         -->
    <bean id="boy" class="beans.Boy" >

        <!-- 基本类型注入 -->
        <property name="name" value="小明"></property>
        <!-- Spring 组件类型注入 ref  -->
        <!-- 依赖参数的内部写法,外部的其他键无法访问 -->
        <property name="dog" >
         <bean id="dog" class="day1.Dog">
            <property name="name" value="吃鸡"></property>
            <property name="age" value="55"></property>
        </bean>
         </property>

    </bean>

    <!-- 依赖参数的外部注入写法 -->
        <bean id="boy1" class="beans.Boy">
            <property name="name" value="小明"></property>
            <property name="dog" ref="dog"></property>
        </bean>
    <bean id="dog" class="day1.Dog"></bean>
</beans>
        <!-- 集合 类型注入:
            list  set   Map
                list 注入:一个value 标签代表一个元素
         -->

        <bean id="setList" class="beans.setList">
            <property name="lists">
                <list>
                <value type="java.lang.String">天下第一</value>
                <value type="java.lang.String">天下第二</value>
                </list>
            </property>

            <property name="dlist">
            <!-- 组件注入集合的方式 -->
            <!--      <list>
                    <ref bean="date"></ref>
                    <ref bean="date"></ref>
                    <null></null>
                </list>
                -->
                <set>
                    <ref bean="date"></ref>
                    <null></null>
                    <ref bean="date"></ref>
                </set>
            </property>

        </bean>

    <bean id="date" class="java.util.Date"></bean>    

        <!-- 注入map 集合 -->
        <bean id="setMap" class="beans.setMap">
            <property name="map">
                <map>
                <entry key-ref="date" value-ref="setList"></entry> <!-- key 和 value 是其他bean时 -->
                 <!-- key 和 value 是字符串或者基本类型时 -->
                <entry key="aa" value="vv"></entry>
                </map>
            </property>
        </bean>

        <bean id="user" class="beans.User">
            <property name="ps">
                <props>
                    <prop key="userName">username</prop>
                    <prop key="passWord">password</prop>
                </props>
            </property>
        </bean>

</beans> 

Spring的配置文件说明的更多相关文章

  1. Spring的配置文件

    Web.xml将会配置Spring的配置文件位置: <servlet>        <servlet-name>x</servlet-name>        & ...

  2. java Spring使用配置文件读取jdbc.properties

    Spring使用配置文件读取jdbc.properties 在beans.xml中加入两个必须的bean [html]<bean id="propertyConfigurer" ...

  3. 使用JDom解析XML文档模拟Spring的配置文件解析

    在J2EE项目中可能会涉及到一些框架的使用,最近接触到了SSH,拿Spring来说配置文件的使用是相当重要的,Spring的配置文件是一个xml文件,Spring是如何读取到配置文件并进行依赖注入的呢 ...

  4. Spring Boot 配置文件详解

    Spring Boot配置文件详解 Spring Boot提供了两种常用的配置文件,分别是properties文件和yml文件.他们的作用都是修改Spring Boot自动配置的默认值.相对于prop ...

  5. Spring boot 配置文件详解 (properties 和yml )

    从其他框架来看 我们都有自己的配置文件, hibernate有hbm,mybatis 有properties, 同样, Spring boot 也有全局配置文件. Springboot使用一个全局的配 ...

  6. Springboot 系列(二)Spring Boot 配置文件

    注意:本 Spring Boot 系列文章基于 Spring Boot 版本 v2.1.1.RELEASE 进行学习分析,版本不同可能会有细微差别. 前言 不管是通过官方提供的方式获取 Spring ...

  7. java web路径和spring读取配置文件

    此篇博客缘起:部署java web系统到阿里云服务器(ubuntu14.04)的时候,有以下两个问题 找不到自定义的property配置文件 上传图片的时候找不到路径 开发的时候是在windows上的 ...

  8. 史上最全的Spring Boot配置文件详解

    Spring Boot在工作中是用到的越来越广泛了,简单方便,有了它,效率提高不知道多少倍.Spring Boot配置文件对Spring Boot来说就是入门和基础,经常会用到,所以写下做个总结以便日 ...

  9. spring boot 配置文件

    spring boot使用一个全局配置文件:主要是以下两种类型 application.properties  :例:server.port=9998 application.yml(YAML)  : ...

  10. Spring之配置文件bean作用域的详细介绍

    Spring的配置文件applicationContext.xml中bean作用域的详细介绍: 1:对象的创建:单例和多例        scope="singleton",默认值 ...

随机推荐

  1. 搭建python的开发环境(采用eclipse的开发工具)在线和离线安装pyDev

    一.首先下载python的开发环境并安装 在这里下载python3.7.2,然后安装在一个指定文件夹,随后,将安装路径配置到环境变量中 验证是否成功 OK! 二.在线安装pyDev工具 三.导入开发环 ...

  2. linux7 安装Docker

    Docker:用白话文简单介绍就是一个集装箱,可以将其运行环境及依赖打包,方便各种场合使用.Docker 让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机 ...

  3. 站在巨人的肩膀上才能看得更加远[Amo]

    本来只是路过,写详细一点. 我看楼主浮躁得不得了.现在什么都不要做了,先去看几遍<不要做浮躁的嵌入式工程师>这篇文章,想清楚了,再动手吧. 我做了个实例,不用ST的库来点LED,解答你的问 ...

  4. vue :src 不显示的解决方案

    一定要将静态资源引入 [ require("@/assets/") ],绑定到 模型绑定的:src 数据中 动态的数据才能有效   <template>   <d ...

  5. 冰蝎动态二进制加密WebShell特征分析

    概述 冰蝎一款新型加密网站管理客户端,在实际的渗透测试过程中有非常不错的效果,能绕过目前市场上的大部分WAF.探针设备.本文将通过在虚拟环境中使用冰蝎,通过wireshark抓取冰蝎通信流量,结合平时 ...

  6. 字符串题汇总(python3)

    1.最小编辑距离 假设有两个字符串s1和s2,计算通过增添.删除.替换三种操作后,从s1转变为s2所需要的操作次数. #coding=utf-8 class Solution: def editDis ...

  7. 条件判断语句(if-else)

    if-else 语法 if-else 语法,只有一个语句块被执行 if 和 else都是Java中的关键字 if 语法 把 if-else 看做一个表达式,程序整体还是顺序执行的 if (boolea ...

  8. 01.Delphi最简单的接口

    我想学习一个插件框架,但是那个框架里面大量用到了接口,于是不得不把接口看一下了.总感觉接口编程这一块非常的绕,每一行都注释了. unit Unit1; interface uses Windows, ...

  9. spark aggregate算子

    spark aggregate源代码 /** * Aggregate the elements of each partition, and then the results for all the ...

  10. 京东首页如何实现pc端和移动端加载不同的html的?

    进入www.jd.com后代码判断是手机的话就跳转m.jd.com let ua = window.navigator.userAgent.toLocaleLowerCase() let murl = ...