javaEE Spring,Spring配置之Bean元素

src/applicationContext.xml(Spring配置文件,Bean元素配置):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd ">

	<!-- 将User对象交给spring容器管理 -->
	<!-- Bean元素:使用该元素描述需要spring容器管理的对象
			class属性:被管理对象的完整类名.
			name属性:给被管理的对象起个名字.获得对象时根据该名称获得对象.  
					可以重复.可以使用特殊字符.(不建议重复)
			id属性: 与name属性一模一样. 
					名称不可重复.不能使用特殊字符.
			结论: 尽量使用name属性.
	  -->
	<bean name="user" class="cn.itcast.bean.User" ></bean>
	
	<!-- 可以导入其他spring配置文件 -->
	<import resource="cn/xxx/demo/applicationContext.xml"/>
	
</beans>

猜你喜欢

转载自blog.csdn.net/houyanhua1/article/details/81947226