Spring学习笔记1
学习内容
配置Spring |
普通属性的注入 |
自定义属性编辑器 |
配置Spring
核心包
日志记录
拷贝Spring配置文件
拷贝Spring日志配置文件
单元测试
为MyEclipse添加XML文件模板
|
普通属性的注入
1.新建一个Bean文件
生成相应的get和set方法 |
2.建立配置文件 applicationContext-Injection_Attribute.xml
|
3.新建单元测试类InjectionTest
|
自定义属性编辑器
作用 | 将spring配置文件中的字符串转换成相应的对象进行注入
|
步骤 | 继承PropertyEditorSuppprt 重写:setAsTest(test) 将属性编辑器注册到spring中 |
实例 | 将字符串转换成时间格式输出 |
1.
新建Bean类Injection_Date.java |
private Date dateValue; 生成其get和set方法 |
2.
配置文件信息applicationContext-Injection_Date.xml |
|
3.
新建类:UtilDatePropertyEditor 继承PropertyEditorSuppprt 重写:setAsTest(test) |
|
4.
注册属性编辑器 注入到CustomEditorConfigurer的Map中,有set方法就可以注入 |
|
5.
单元测试 |
|