Spring配置(applicationContext.xml)

applicationContext.xml

别名

方法一:单独标签

<bean id="hello" class="com.my.pjo.Hello">
    <constructor-arg name="str" value="Andrew"/>
</bean>
		<!--别名-->
    <alias name="hello" alias="Spring"/>
</beans>

方法二(推荐):在bean标签内name设置

<bean id="hello" class="com.my.pjo.Hello" name="hello2,hello3">
    <constructor-arg name="str" value="Andrew"/>
</bean>

Bean配置

使用Spring来创建对象,在Spring这些都成为Bean
    bean 就是一个对象,Spring以Ioc为基础进行封装
    类型 变量名=new 类型();
    Hello hello=new Hello();
    id = 变量名
    class = new 的对象,全限定名:包名+类名
    property 相当于给对象中的属性设置一个值
	name:别名,可同时取多个别名

import

一般用于团队开发使用,它可以将多个配置文件,导入合并为一个。
虚拟情景:项目中多人开发,几个人负责不同类的开发,不同类需要注册在不同的bean中,我们可以利用import将所有人的applicationContext.xml合并为一个总的。使用的时候,直接使用总的配置就可以了
内容相同也会智能合并。

 <import resource=""/>

おすすめ

転載: blog.csdn.net/fhuqw/article/details/121274732