How to move location of Atomikos's tm.out and

2020-07-08 07:15发布

问题:

I'm running a J2SE application that uses Atomikos which dumps it's numerous log files to the current directory. I'd like to move the location of these files to "/tmp", but I cannot locate a configuration property that I can set from within my Spring XML config file.

The Atomikos documentation references a property:

com.atomikos.icatch.output_dir

Which seems exactly what I need, but how to set from Spring it without a jta.properties file? Here is my transaction manager config:

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager" ref="atomikosTransactionManager" />
    <property name="userTransaction" ref="atomikosUserTransaction" />
</bean>

<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
    init-method="init" destroy-method="close">
    <!-- When close is called, should we force transactions to terminate? -->
    <property name="forceShutdown" value="false" />
</bean>

<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
    <!-- Number of seconds before transaction timesout. -->
    <property name="transactionTimeout" value="30" />
</bean>

回答1:

The property in question must be set on the singleton instance of the transactionService -- an object that is normally created on-demand by the user transaction manager:

<bean id="userTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp"
    init-method="init" destroy-method="shutdownForce">
    <constructor-arg>
        <!-- IMPORTANT: specify all Atomikos properties here -->
        <props>
            <prop key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop>
            <prop key="com.atomikos.icatch.output_dir">target/</prop>
            <prop key="com.atomikos.icatch.log_base_dir">target/</prop>
        </props>
    </constructor-arg>
</bean>

Now the property is set. But in order to ensure you don't have two transaction services running you must also modify the user transaction manager bean as follows:

<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
    init-method="init" destroy-method="close" depends-on="userTransactionService">
    <!-- When close is called, should we force transactions to terminate? -->
    <property name="forceShutdown" value="false" />
    <!-- Do not create a transaction service as we have specified the bean in this file -->
    <property name="startupTransactionService" value="false" />
</bean>