سؤال

أحاول ترقية مشروعي ولذا فقد توصلت إلى المعاملات.وهذه هي الطريقة التي فعلت بها حتى الآن.

<bean id="userServiceTarget" class="com.forgin.service.UserServiceImpl">
    <property name="userDAO" ref="userDAO" />
</bean>

<bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="target" ref="userServiceTarget" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="transactionAttributes">
            <props>
                <prop key="get*">PROPAGATION_SUPPORTS</prop>
                <prop key="is*">PROPAGATION_SUPPORTS</prop>
                <prop key="save*">PROPAGATION_REQUIRED</prop>
                <prop key="remove*">PROPAGATION_REQUIRED</prop>
            </props>
        </property>
</bean>

لقد قمت بتغيير سمات المعاملة مثل هذا أدناه، لكنني لست متأكدًا تمامًا من كيفية ربط الخدمة بهذا بالضبط txAdvice.لأنني عمومًا أمتلك سمات معاملات مختلفة للخدمات المختلفة، لذا أعتقد أنه يجب أن يكون هناك أكثر من واحدة txAdvice.هل هناك طريقة لكيفية قول @Transactional لاستخدام هذا txAdvice معين؟

<tx:advice id="txAdvice">
    <tx:attributes>
        <tx:method name="get*" read-only="true" />
        <tx:method name="is*" read-only="true" />
        <tx:method name="save*" propagation="REQUIRED" />
        <tx:method name="remove*" propagation="REQUIRED" />
    </tx:attributes>
</tx:advice>
هل كانت مفيدة؟

المحلول

حسنًا، لقد اكتشفت ذلك..هذا سياتي الي.هاها..أنا فقط بحاجة لتقديم إضافية aop:advisor و aop:pointcut.بهذه البساطة.

<aop:config>
    <aop:pointcut id="userOperation"
            expression="execution(* com.forgin.service.UserServiceImpl.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
        <aop:pointcut id="differentOperation"
            expression="execution(* com.forgin.service.DifferentServiceImpl.*(..))" />
    <aop:advisor advice-ref="txAdviceDifferent" pointcut-ref="differentOperation" />
</aop:config>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top