3

私はラバが初めてです。春の冬眠ラバのセットアップがあります。3 つの Web サービスがあるとします。目的は、これらすべての Web サービスを Mule フローで呼び出して、3 つすべてがトランザクションに含まれるようにすることです。そのため、3 番目の Web サービスが失敗した場合、前の 2 つは自動的にロールバックされるとします。

これが私が試したコードスニペットです。my mule-flow.xml( currently I have only one webservice,kindly let me know how can I add multipe webservice call in flow?)

<spring:beans>
 <spring:import resource="classpath:spring-mule.xml"/>
 <spring:import resource="classpath:applicationContext-persistence.xml"/>
</spring:beans>

<flow name="addCustomer" doc:name="addCustomer">
<http:inbound-endpoint exchange-pattern="request-response"
address="http://localhost:8081/pos/addCustomer" doc:name="HTTP" />

<cxf:simple-service serviceClass="com.proj.pos.webservice.interfac.CustomerService" doc:name="SOAP"/>
<component ><spring-object bean="customerService"/></component>
</flow>

</mule>

私の spring-mule.xml

<bean id="customerService"  class="com.proj.pos.webservice.implementation.CustomerServiceImpl">
    <property name="cusDao" >
    <ref local="customerDao"/>
    </property>
    </bean>

My:applicationContext-persistence.xml

     <bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe" />
<property name="username" value="xyz" />
<property name="password" value="xyz" />
</bean> 

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="datasource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
                <prop key="hibernate.connection.release_mode">auto</prop>
            </props>
        </property>
    </bean>

    <tx:annotation-driven />
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

     <bean id="customerDao" class="com.proj.pos.dao.implementation.CustomerDaoImpl">
    <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property>
    </bean>

私のCustomerServiceImpl

@WebService(endpointInterface = "com.proj.pos.webservice.interfac.CustomerService",
        serviceName = "CustomerService")
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerDao cusDao;

    @Transactional  //NOTE:USING THIS ANNOTATION I AM ABLE TO ACHIEVE THE BELOW METHOD //IN TRANSACTION,BUT I BELEIVE THIS FEATURE WILL NOT WORK IF WE HAVE MULTIPLE WEBSERVICE CALL
    @Override
    public Customer addCustomer(CustomerDto dto) {
        Customer customer=new Customer(dto.getCustomerId(), dto.getFname(), dto.getLname(), dto.getAge(), dto.getDateOfBirth(), dto.getAddress());
        customer.setCustomerId(cusDao.persist(customer));
         return customer;
    }

    public CustomerDao getCusDao() {
        return cusDao;
    }

    public void setCusDao(CustomerDao cusDao) {
        this.cusDao = cusDao;
    }

}

解決策を教えてください。ありがとう

4

2 に答える 2

0

私の理解によると、3 つ以上の webservices 呼び出しといくつかの db 操作があります。サービス呼び出しが失敗した場合にロールバックします。

SpringTransactionFactory に対して以下のように Spring Bean を記述し、transationManager プロパティを設定します (applicationContext-persistence.xml から参照)。

<spring:beans>
 <spring:import resource="classpath:spring-mule.xml"/>
 <spring:import resource="classpath:applicationContext-persistence.xml"/>
 <spring:bean id = "transactionFactory" class = "org.mule.module.spring.transaction.SpringTransactionFactory">
    <spring:property ref="transactionManager" name=""></spring:property>
 </spring:bean>
</spring:beans>

以下のように inboundEndpoint に tansactionfactory ref を追加します。

<http:inbound-endpoint exchange-pattern="request-response"
                address="http://localhost:8081/pos/addCustomer" doc:name="HTTP" >
                <custom-transaction action="ALWAYS_BEGIN" factory-ref="transactionFactory"/>
                </http:inbound-endpoint>

完全なフローは、単一のトランザクションと inclouding dao クラスになります。

于 2015-08-27T08:04:35.243 に答える