1 Autowire自动装配
1.1 使用:只需在<bean>中使用autowire元素
<bean ></bean>
2.2 依赖关系
2.2.1 Spring允许通过使用depends-on属性设定bean的前置bean,依赖的bean必须在本bean实例化前创建好
2.2.2 如果依赖多个bean,可以使用逗号或空格的方式隔开
<!-- bean的依赖关系 -->
<bean ></bean>
3.2 可以使用scope进行配置
4 使用外部属性文件
4.1 bean配置有时需要系统部署信息,如文件路径、数据源配置信息等,需要将其与bean配置文件分离
4.2 Spring 提供了一个 PropertyPlaceholderConfigurer 的 BeanFactory 后置处理器,可以使用外部属性文件,使用${var}
4.3 spring2.5后,可通过<context:property-placeholder> 直接使用PropertyPlaceholderConfigurer ,使用locaiton属性指明配置文件路径,需要引入context schema
<!-- 引入外部属性文件 -->
<context:property-placeholder location="db.properties"/>
db.properties与properties.xml必须同级目录,否则会报错,
class path resource [db.properties] cannot be opened because it does not exist
<!-- 使用外部属性配置文件-->
<context:property-placeholder location="classpath:db.properties"/>
<bean ></property>
</bean>