Spring 配置说明

Spring 配置说明

1.<alias/>(起别名)

<?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
        https://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="hello" class="com.xiaofu.pojo.Hello">
        <property name="str" value="Spring"/>
    </bean>
    
<!--    给上面的bean标签 起了一个别名叫xiaofu-->
    <alias name="hello" alias="xiaofu"/>
</beans>

 起了别名之后 在获取bean对象的时候 就可以直接用xiaofu也能拿到

2.<bean/>(配置):

<?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
        https://www.springframework.org/schema/beans/spring-beans.xsd">

<!--    id: bean的唯一标识
        class: bean 对象对应的全限定名:包名 + 类型
        name: 也是别名 可以起多个别名用,号分开
-->
    <bean id="user" class="com.xiaofu.pojo.Hello" name="u1,u2">
        
    </bean>

</beans>

3.<import/>(导入):

这个import,一般用于团队开发使用,他可以将多个配置文件,导入合并为一个假设,现在项目中有多个人开发这三个人复制不同的类开发,

不同的类需要注册在不同的bean中我们可以利用import将所有人的beans.xml合并为一个总的!

<!--这样就导入了一个外部的配置文件-->
    <import resource="beans.xml"/>
原文地址:https://www.cnblogs.com/love2000/p/14236215.html