2017-01-16 2 views
0

現在、xmlの設定から、Java設定のSpringアプリケーションを使用して注釈を完成させています。アノテーションのアプローチでは、@Transactionalを達成できますが、それぞれの方法ごとに記述する必要があります。Spring Spring 4.3.4のバージョンでプログラミングによるトランザクションの設定

XMLでは(OLD)を設定しました。

<bean id="txProxyTemplate" abstract="true" 
     class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> 
     <property name="transactionManager"> 
      <ref bean="transactionManager" /> 
     </property> 
     <property name="transactionAttributes"> 
      <props> 
       <prop key="delete*">PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED</prop> 
       <prop key="update*">PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED</prop> 
       <prop key="save*">PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED</prop> 
       <prop key="get*">PROPAGATION_SUPPORTS,ISOLATION_READ_COMMITTED,readOnly</prop> 
       <prop key="is*">PROPAGATION_SUPPORTS,ISOLATION_READ_COMMITTED,readOnly</prop> 
       <!--<prop key="*">PROPAGATION_REQUIRED</prop> --> 
      </props> 
     </property> 
    </bean> 

のTransactionManager txProxyTemplate

<bean id="xxxxSVC" parent="txProxyTemplate"> 
     <property name="target"> 
      <bean class="XXX.XXX.XXX.SVCImpl"> 
       <property name="xxxxDao" ref="xxxDao"></property> 

      </bean> 
     </property> 
    </bean> 

org.springframework.orm.hibernate3.HibernateTransactionManager、各サービス・クラスの親クラスです。

Java設定で同様のコードを設定する方法をお勧めします。あなたの貴重な時間を過ごしていただきありがとうございます。

@Barathコメント

@Bean 
    public TransactionProxyFactoryBean setTransactionProperties() throws IOException { 
     TransactionProxyFactoryBean transactionProxyFactoryBean = new TransactionProxyFactoryBean(); 
     transactionProxyFactoryBean.setTransactionManager(transactionManager(sessionFactory())); 
     Properties transactionAttributesProps = new Properties(); 
     transactionAttributesProps.setProperty("delete*", "PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED"); 
     transactionAttributesProps.setProperty("update*", "PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED"); 
     transactionAttributesProps.setProperty("save*", "PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED"); 
     transactionAttributesProps.setProperty("get*", "PROPAGATION_SUPPORTS,ISOLATION_READ_COMMITTED,readOnly"); 
     transactionAttributesProps.setProperty("is*", "PROPAGATION_SUPPORTS,ISOLATION_READ_COMMITTED,readOnly"); 
     transactionProxyFactoryBean.setTransactionAttributes(transactionAttributesProps); 

     transactionProxyFactoryBean.afterPropertiesSet(); 
     return transactionProxyFactoryBean; 
    } 

サービス層は、Nクラスを含むことができ、各サービス実装クラスで構成する方法、我々は単一のためにそれを使用することができます。 setTarget(Object target)メソッドがあります。今度はどのようにしてN個のクラスをすべて構成できますか?どうすれば設定できますか?

+0

あなたは、単にこれは私が理解して複雑である性質 – Barath

答えて

0

この場合のサンプル構成:

@Bean 
    public TransactionProxyFactoryBean txProxyTemplate(){ 

     TransactionProxyFactoryBean txFactory=new TransactionProxyFactoryBean(); 
     txFactory.setTransactionManager(new JpaTransactionManager()); // any transcation manager 
     txFactory.setTransactionAttributes(properties()); 
     return txFactory; 

    } 

    @Bean 
    Properties properties(){ 
     Properties properties=new Properties(); 
     properties.put("delete*", "PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED"); 
     //set al lthe properties 
     return properties; 
    } 


    @Bean 
    public TransactionProxyFactoryBean xxxxSVC(TransactionProxyFactoryBean txFactory){ 
     txFactory.setTarget(testEntity()); 
     return txFactory; 
    } 

    @Bean 
    TestEntity testEntity(){ 
     return new TestEntity(); 
    } 
+0

でそれぞれのクラスのJavaの構成にXMLを変換するために@Beanを利用することができます。 xmlからjava設定に移行するときは、@ Transcational自体を先に進めてください。 – Barath

+0

@Bean TestEntity testEntity(){ return new TestEntity(); } – Nageshwar

+0

そのサンプルです。コンフィグレーションごとにターゲットを設定することができます – Barath

関連する問題