现在的位置: 首页 > 综合 > 正文

Spring abstract=”true” merge=”true”

2018年01月26日 ⁄ 综合 ⁄ 共 1740字 ⁄ 字号 评论关闭

abstract="true"

由于设置bean定义中设置了abstract="true",所以Spring容器就不对其进行初始化。

只是在此起了模板的作用,供其他bean继承,所以父bean的属性在类体中可以不定义,直接在bean的声明中以<proerty/>声明即可。

子bean继承他后需要在提供对应的属性和set方法即可,在子bean中就可获取从父bean继承来的值.

   <bean id="baseLocalTxProxy" abstract="true"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager"
            ref="localTransactionManager" />
        <property name="transactionAttributes">
            <props>
                <prop key="add*">PROPAGATION_REQUIRED</prop>
                <prop key="set*">PROPAGATION_REQUIRED</prop>
                <prop key="new*">PROPAGATION_REQUIRED</prop>
                <prop key="save*">PROPAGATION_REQUIRED</prop>
                <prop key="remove*">PROPAGATION_REQUIRED</prop>
                <prop key="delete*">PROPAGATION_REQUIRED</prop>
                <prop key="update*">PROPAGATION_REQUIRED</prop>
                <prop key="merge*">PROPAGATION_REQUIRED</prop>
                <prop key="modify*">PROPAGATION_REQUIRED</prop>
                <prop key="submit">PROPAGATION_REQUIRED</prop>
                <prop key="list*">PROPAGATION_SUPPORTS,readOnly</prop>
                <prop key="query*">PROPAGATION_SUPPORTS,readOnly</prop>
                <prop key="search*">PROPAGATION_SUPPORTS,readOnly</prop>
                <prop key="load*">PROPAGATION_SUPPORTS,readOnly</prop>
                <prop key="find*">PROPAGATION_SUPPORTS,readOnly</prop>
                <prop key="get*">PROPAGATION_SUPPORTS,readOnly</prop>
            </props>
        </property>
    </bean>

<bean id="shopPickerServiceImpl" parent="baseLocalTxProxy">
        <property name="target">
            <bean class="com.ibm.bpm.wle.module.maindata.biz.impl.ShopPickerServiceImpl"
                autowire="byName">
                <property name="shopPickerDao" ref="shopPickerDaoImpl"></property>
            </bean>
        </property>
        <property name="transactionAttributes">
            <props merge="true">
                <prop key="save*">PROPAGATION_SUPPORTS,readOnly</prop>
                <prop key="list*">readOnly</prop>
            </props>
        </property>
    </bean>

merge="true"

子bean中<prop key="save*">PROPAGATION_SUPPORTS,readOnly</prop>和父bean中的save*相同 那么

子bean会覆盖父bean 的save*.

抱歉!评论已关闭.