注册Spring批处理事务

注册Spring批处理事务,spring,spring-batch,spring-transactions,Spring,Spring Batch,Spring Transactions,我的要求是需要将两个数据源连接到Spring批处理应用程序。 1) 一个用于Spring批处理作业和执行存储 2) 一个用于业务数据存储、处理和检索。 我知道实现这一目标有很多解决方案。但我通过将第二个数据源设置为主数据源实现了这一点。问题是第二个数据源不在事务范围内,而是提交每个sql语句,特别是通过jdbctemplate执行。,因为我无法编辑我的问题。我正在详细地写另一篇文章 我的要求是我需要有两个数据源连接到Spring批处理应用程序 1) 一个用于Spring批处理作业和执行存储 2)

我的要求是需要将两个数据源连接到Spring批处理应用程序。
1) 一个用于Spring批处理作业和执行存储
2) 一个用于业务数据存储、处理和检索。

我知道实现这一目标有很多解决方案。但我通过将第二个数据源设置为主数据源实现了这一点。问题是第二个数据源不在事务范围内,而是提交每个sql语句,特别是通过jdbctemplate执行。

,因为我无法编辑我的问题。我正在详细地写另一篇文章
我的要求是我需要有两个数据源连接到Spring批处理应用程序
1) 一个用于Spring批处理作业和执行存储
2) 一个用于业务数据存储、处理和检索

env context.xml中,我有以下配置

<!-- Enable annotations-->
<context:annotation-config/>

<bean primary="true" id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:/DB2XADS"/>
</bean>

<!-- Creating TransactionManager Bean, since JDBC we are creating of type 
    DataSourceTransactionManager -->
<bean id="transactionManager" primary="true"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

<!-- jdbcTemplate uses dataSource -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource" /> 
</bean>

<bean id="batchTransactionManager" 
    class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/>

<bean id="transactionTemplate"
    class="org.springframework.transaction.support.TransactionTemplate">
    <property name="transactionManager" ref="transactionManager" />
</bean>

在上面的代码中,我试图插入数据,并且立即抛出一个异常,这意味着插入应该发生,但提交不会发生。因此,我们将无法看到任何数据,但不幸的是,提交正在发生。请提供一些帮助

你能解释一下吗..通过分享一些codeHi Yogi,我无法编辑我问的问题,因此我将我的问题详细发布,作为对同一问题的回答。所以,请看一看,并引导我提前感谢
<tx:annotation-driven transaction-manager="transactionManager" />

<!-- jdbcTemplate uses dataSource -->
<bean id="batchDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:/MySqlDS"/>
</bean>

<bean class="com.honda.pddabulk.utility.MyBatchConfigurer">
    <property name="dataSource" ref="batchDataSource" />
</bean>

<!-- Use this to set additional properties on beans at run time -->
<bean id="placeholderProperties"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:/org/springframework/batch/admin/bootstrap/batch.properties
            </value>
           <value>classpath:/batch/batch-mysql.properties</value>
            <value>classpath:log4j.properties</value>
        </list>
    </property>
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    <property name="ignoreResourceNotFound" value="true"/>
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
    <property name="order" value="1"/>
</bean>

<!-- Overrider job repository -->
<bean id="jobRepository"
      class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    <property name="databaseType" value="mysql"/>
    <property name="dataSource" ref="batchDataSource"/>
    <property name="tablePrefix" value="${batch.table.prefix}"/>
    <property name="maxVarCharLength" value="2000"/>
    <property name="isolationLevelForCreate" value="ISOLATION_SERIALIZABLE"/>
    <property name="transactionManager" ref="batchTransactionManager"/>
</bean>

<!-- Override job service -->
<bean id="jobService" class="org.springframework.batch.admin.service.SimpleJobServiceFactoryBean">
    <property name="tablePrefix" value="${batch.table.prefix}"/>
    <property name="jobRepository" ref="jobRepository"/>
    <property name="jobLauncher" ref="jobLauncher"/>
    <property name="jobLocator" ref="jobRegistry"/>
    <property name="dataSource" ref="batchDataSource"/>
</bean>

<!-- Override job launcher -->
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
    <property name="taskExecutor" ref="jobLauncherTaskExecutor" />
</bean>

<task:executor id="jobLauncherTaskExecutor" pool-size="21" rejection-policy="ABORT" />

<!-- Override job explorer -->
<bean id="jobExplorer"
      class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
    <property name="tablePrefix" value="${batch.table.prefix}"/>
    <property name="dataSource" ref="batchDataSource"/>
</bean>
<context:component-scan base-package="com.honda.*">
     <context:exclude-filter type="regex" 
               expression="com.honda.pddabulk.utility.MyBatch*" /> 
</context:component-scan>
@Transactional
public void checkInsertion() throws Exception{
    try{
        jdbcTemplate.update("INSERT INTO TABLE_NAME(COLUMN1, COLUMN2) VALUES( 'A','AF' );
        throw new PddaException("custom error");
    }catch(Exception ex){
        int count=jdbcTemplate.update("ROLLBACK");
        log.info("DATA HAS BEEN ROLLBACKED SUCCESSFULLY... "+count);        
        throw ex; 
    }

}