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:context="http://www.springframework.org/schema/context"
  5.  
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://www.springframework.org/schema/context
  9. http://www.springframework.org/schema/context/spring-context.xsd">
  10.  
  11. <!-- <context:component-scan base-package="com.chinasofti.bean"></context:component-scan> -->
  12.  
  13. <!-- 构造器方式 -->
  14. <bean id="dog" class="day1.Dog">
  15. <!-- 有参的类: constructor-arg 标签代表有参构造,index对应第几个参数,value是值 -->
  16. <constructor-arg index="0" value="杀魔爷"></constructor-arg>
  17. <constructor-arg index="1" value="888"></constructor-arg>
  18.  
  19. </bean>
  20.  
  21. <!-- 静态工厂方式 -->
  22. <bean id="product" class="beans.staticFactorys" factory-method="getProduct"></bean>
  23.  
  24. <!-- 非公共类 -->
  25. <bean id="div" class="beans.Div"></bean>
  26.  
  27. <!-- 普通类的方法 返回的对象 -->
  28. <bean id="factory" class="beans.Factory" ></bean>
  29. <bean id="product2" factory-bean="factory" factory-method="getProduct"></bean>
  30.  
  31. <!-- 导入其他的配置文件-->
  32. <import resource="ac.xml"/>
  33. <!-- 默认情况下每个bean 的scope的值是 singleton 即 单例模式,该模式下容器只存在一个bean
  34. 在单例模式下属性 lazy-init 可以决定bean的创建事件,默认:false 时随着IOC 容器的创建而创建
  35. (ApplicationContext ac=new ClassPathXmlApplicationContext("ac.xml");)
  36. 该值为true 时 ,则第一场获取对象 (getBean()) 是创建对象
  37.  
  38. scope 的值是 prototype 时 即 多例模式 其 lazy-init 的值就只能是 true
  39.  
  40. init-method: 初始化方法
  41. destory-method: 销毁方法
  42. -->
  43. <bean id="dog" class="day1.Dog" scope="singleton" init-method="setName" destroy-method="destory"/>
  44.  
  45. <!-- property 标签 可以给初始化成员变量 -->
  46.  
  47. <!-- 1.Boy boy=new Boy();
  48. 2.boy.setName(小明)
  49. boy.setDog(new Dog());
  50. -->
  51. <bean id="boy" class="beans.Boy" >
  52.  
  53. <!-- 基本类型注入 -->
  54. <property name="name" value="小明"></property>
  55. <!-- Spring 组件类型注入 ref -->
  56. <!-- 依赖参数的内部写法,外部的其他键无法访问 -->
  57. <property name="dog" >
  58. <bean id="dog" class="day1.Dog">
  59. <property name="name" value="吃鸡"></property>
  60. <property name="age" value="55"></property>
  61. </bean>
  62. </property>
  63.  
  64. </bean>
  65.  
  66. <!-- 依赖参数的外部注入写法 -->
  67. <bean id="boy1" class="beans.Boy">
  68. <property name="name" value="小明"></property>
  69. <property name="dog" ref="dog"></property>
  70. </bean>
  71. <bean id="dog" class="day1.Dog"></bean>
  72. </beans>
  73. <!-- 集合 类型注入:
  74. list set Map
  75. list 注入:一个value 标签代表一个元素
  76. -->
  77.  
  78. <bean id="setList" class="beans.setList">
  79. <property name="lists">
  80. <list>
  81. <value type="java.lang.String">天下第一</value>
  82. <value type="java.lang.String">天下第二</value>
  83. </list>
  84. </property>
  85.  
  86. <property name="dlist">
  87. <!-- 组件注入集合的方式 -->
  88. <!-- <list>
  89. <ref bean="date"></ref>
  90. <ref bean="date"></ref>
  91. <null></null>
  92. </list>
  93. -->
  94. <set>
  95. <ref bean="date"></ref>
  96. <null></null>
  97. <ref bean="date"></ref>
  98. </set>
  99. </property>
  100.  
  101. </bean>
  102.  
  103. <bean id="date" class="java.util.Date"></bean>
  104.  
  105. <!-- 注入map 集合 -->
  106. <bean id="setMap" class="beans.setMap">
  107. <property name="map">
  108. <map>
  109. <entry key-ref="date" value-ref="setList"></entry> <!-- key 和 value 是其他bean时 -->
  110. <!-- key 和 value 是字符串或者基本类型时 -->
  111. <entry key="aa" value="vv"></entry>
  112. </map>
  113. </property>
  114. </bean>
  115.  
  116. <bean id="user" class="beans.User">
  117. <property name="ps">
  118. <props>
  119. <prop key="userName">username</prop>
  120. <prop key="passWord">password</prop>
  121. </props>
  122. </property>
  123. </bean>
  124.  
  125. </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 数据处理 对csv文件进行数据处理

    数据如下图: 用python对数据进行处理: #读取csv文件内容并进行数据处理 import os import csv import datetime import re from itertoo ...

  2. [Codeforces]1263D Secret Passwords

    题目 One unknown hacker wants to get the admin's password of AtForces testing system, to get problems ...

  3. Verilog 2001 `default_nettype none

    在Verilog 1995規定,對於沒宣告的信號會自動視為wire,這樣常常造成debug的困難,Verilog 2001另外定義了`default_nettype none,將不再自動產生wire. ...

  4. Java 定时循环运行程序

    Timer 和 ScheduledExecutorSeruvce 都能执行定时的循环任务,有函数 scheduleAtFixedRate.但是,如果任务运行时间较长,超过了一个周期时长,下一个任务就会 ...

  5. NIO三大组件简介

    NIO简介 NIO 是面向缓冲区(或者说面向块)编程的, 因为Buffer底层本质上就是内存块.数据被读取到一个缓冲区, 稍后再被它处理, 需要时数据可在缓冲区前后移动, 从而增加了处理过程中的灵活性 ...

  6. Linux服务器命令大全

    快捷提示键: table 查看文件夹:  ls , ls –all ,ls –l,ll 进入某个文件夹: cd usr/local 回到root 目录 : cd /root/ 回到根目录:cd / 回 ...

  7. 吴裕雄--天生自然java开发常用类库学习笔记:线程常用的操作方法

    class MyThread implements Runnable{ // 实现Runnable接口 public void run(){ // 覆写run()方法 for(int i=0;i< ...

  8. 安装scrapy框架报错是常见问题

    还好,本人只碰到其中一个bug,以下是此次安装经验 环境 py3.4 windows7 64位 安装有VS2010 pip包管理(pycharm) 报错信息 安装lxml过程中报错:error: co ...

  9. TX2开发板Ubuntu16.04设置静态IP

    TX2开发板Ubuntu16.04设置静态IP  https://www.cnblogs.com/qilai/p/11285445.html 首先打开一个Terminal输入 ifconfig 查看自 ...

  10. Oracle SQL存储过程结构、异常处理示例

    -- 存储过程结结构. -- EXCeption不是存储过程必须部分,可以用作本存储过程的异常处理,但如果没有异常处理,出了异常将会终止程序 CREATE PROCEDURE procedure_na ...