Spring 关键配置体现在其核心配置文件中,一般Spring默认的核心配置就是applicationContent.xml.这里可以配置各个bean彼此间的依赖关系。同时 ,Spring可以通过这个文件知道各个bean基本信息,并在运行过程中装配起来。
eg:applicationContent.xml 通过关键字c即可获取Category对象,该对象获取的时候,即被注入了字符串"category 1“到name属性中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean name="c" class="com.how2java.pojo.Category">
<property name="name" value="category 1" />
</bean>
<bean id="chinese" class ="com.people.chinese"></bean></beans>
<beans>可以包含多个<bean > ,<bean>定义一个bean如何被装配到Spring容器中(任何一个java对象均可作为bean进行定义)。id属性为指定bean唯一标识符,在整个Spring容器中必须是唯一的。class为指定bean的具体实现类。
Bean之间的依赖配置
实际上,不同bean之间往往有一定的依赖关系。这个时候就需要进行依赖配置了,具体可参考我的上一篇文章