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>
- 
bean对应Java类,指定由spring管理的类。 <!-- id:bean的唯一标识符 class:bean所对应的类的全限定名(包名+类名) name:别名,可以取多个别名用","、" "、";"分隔(逗号、空格、分号)。 --> <bean id="hello" class="com.maple.pojo.Hello" name="he,hi"> <property name="name" value="枫叶"/> </bean>
- 
alias:给bean配置别名(感觉完全多余) <alias name="hello" alias="hello2"/>
- 
import:一般用于团队开发,可以将多个配置文件导入合并为一个配置文件。 <import resource="beans2.xml"/> <import resource="beans3.xml"/> <import resource="beans4.xml"/>
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号