2007-11-08
Spring高级编程工厂介绍(一)
最近手头的项目刚验收完成,有了很多空余时间,第一次写blog有什么不对的地方请大家指正。
org.springframework.beans.factory.config.PropertyPathFactoryBean是一个很有用Bean工厂,大家在项目开发中用的比较多的依赖注入是对象实例注入,如果一个Bean构造函数中或方法中的参数不是一个对象而是普通的值或者是某个对象的一个属性,这时候就需要用到PropertyPathFactoryBean:
以后会继续更新!
xml 代码
- <bean id="person" class="com.test.Person" />
- <bean id="person.address.city" class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
- <property name="targetObject">
- <ref local="person" />
- property>
- <bean id="xxxBean" class="com.test.xxxBean">
- <property name="cityName">
- <ref local="person.address.city" />
- property>
- bean>
类com.test.Person中有个address类型的属性,而address中又有一个String类型的city属性,上面的配置是将city属性注入到
com.test.xxxBean的cityName属性中。
顺便提一下这里fckeditor好像有问题,编辑的内容有时候提交掉,代码编辑器会提交后会掉符号尤其是“>”,不知道其他人有
没有遇到过这种情况。
org.springframework.beans.factory.config.FieldRetrievingFactoryBean能够获取类中的静态域变量,使用这个工厂在来注入常量很方便,代码如下:
xml 代码
- <bean id="max-long" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
- <property name="staticField">
- <value>java.lang.Long.MAX_VALUEvalue>
- property>
- bean>
注入的时候只需要声明式的调用"max-long"来注入就行了。
发表评论
- 浏览: 2034 次
- 性别:

- 来自: 武汉

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
Spring2.5正式版发布了
不错啊,在逐渐走向完美。
-- by eye_accpjiang -
Spring2.5正式版发布了
开始学习新版
-- by arust -
Powerdesign杂记(转)
-- by zorro






评论排行榜