zoukankan      html  css  js  c++  java
  • Spring配置文件

    Spring配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
        <!--    使用spring导入包    -->
        <bean id="hello" class="com.maple.pojo.Hello">
            <!--1. 下标赋值-->
            <!--<constructor-arg index="0" value="枫叶"/>-->
            <!--2. 类型赋值,不建议使用-->
            <!--<constructor-arg type="java.lang.String" value="枫叶"/>-->
            <!--3. 通过参数名赋值-->
            <constructor-arg name="name" value="枫叶"/>
            <!--不指定constructor-arg会使用无参构造器初始化,property通过set方法给属性赋值-->
            <!--<property name="name" value="Spring"/>-->
        </bean>
        <!--
        id:bean的唯一标识符
        class:bean所对应的类的全限定名(包名+类名)
        name:也是别名,可以取多个别名用","、" "、";"分隔(逗号、空格、分号)。
        -->
        <bean id="hello1" class="com.maple.pojo.Hello" name="he,hi">
            <property name="name" value="枫叶"/>
        </bean>
        <alias name="hello" alias="hello2"/>
        <import resource="beans2.xml"/>
        <import resource="beans3.xml"/>
        <import resource="beans4.xml"/>
    </beans>
    
    1. bean对应Java类,指定由spring管理的类。

      	<!--
          id:bean的唯一标识符
          class:bean所对应的类的全限定名(包名+类名)
          name:别名,可以取多个别名用","、" "、";"分隔(逗号、空格、分号)。
          -->
          <bean id="hello" class="com.maple.pojo.Hello" name="he,hi">
              <property name="name" value="枫叶"/>
          </bean>
      
    2. alias:给bean配置别名(感觉完全多余)

      <alias name="hello" alias="hello2"/>
      
    3. import:一般用于团队开发,可以将多个配置文件导入合并为一个配置文件。

      	<import resource="beans2.xml"/>
          <import resource="beans3.xml"/>
          <import resource="beans4.xml"/>
      
  • 相关阅读:
    Python 面向对象(类与对象)
    修改Centos文 7件夹所在组及权限(不同用户共用一个文件夹)
    CGPoint,CGSize,CGRect
    关于投资币圈的思考和微信群问答干货整理
    数字货币合约交易基础知识
    比特币成长大事记
    健康医疗笔记(四)癌症知识
    ​阿德勒心理学《被讨厌的勇气》一切烦恼皆源于人际关系
    免费学术论文网站Sci-Hub
    数字货币交易所开发笔记3-撮合引擎开发
  • 原文地址:https://www.cnblogs.com/junlinsky/p/12822230.html
Copyright © 2011-2022 走看看