今天在做SSH框架Demo实例时,在ApplicationResources.properties文件时对<refbean>与<reflocal>感到不解,经查找资料才弄明白,如下:

< bean id = "userDAOProxy" 

        class = "org.springframework.transaction.interceptor.TransactionProxyFactoryBean" > 

        < property name = "transactionManager" > 

            < ref bean = "transactionManager" /> 

        </ property > 

        < property name = "target" > 

            < ref local = "UserDAO" /> 

        </ property > 

    </ bean >

1、用local属性指定目标bean可以利用xml解析器的能力在同一个文件中验证xmlid引用.如果在同一个文件中没有匹配的元素,xml解析器就会产生一个error,所以如果目标bean在同一个xml文件中,那么用local形式是最好的选择.

2、可以这么说,<refbean是寻找全局中的bean;<reflocal是寻找本xml文件中的bean

3、<ref>提供了如下几方面的属性:

1)bean:在当前SpringXML配置文件中,或者在同一BeanFactory(ApplicationContext)中的其他JavaBean中.

2)local:在当前SpringXML配置文件中.其依赖的JavaBean必须存在于当前SpringXML培植文件中.如果借助于SpringIDE,则在编译期可以对其依赖的JavaBean进行验证。基于local方式,开发者能够使用到XML本身提供的优势,而进行验证。

3)parent:用于指定其依赖的父JavaBean定义。