当没有使用事务

时间:2016-09-01 13:05:27

标签: spring transactions gigaspaces

我正在开发一个使用引擎盖下弹簧的gigaspace xap应用程序。 gigaspaces提供的jini事务管理器不支持可序列化。

我有一个使用spring-batch处理文件的类。以下是调用作业的方式

public class FileProcessor implements BasicFileProcessor {
    @Value("${feeddownload.basedir}")
    private String baseDir;
    @Autowired
    private JobLauncher jobLauncher;
    @Autowired
    private Job cmJob;
    @Autowired
    private MapJobRepositoryFactoryBean repositoryFactoryBean;

    @Override
    public void process(RiskRunCompletion riskRunCompletion, VersionedSliceName versionedSliceName, GigaSpace gigaSpace) {
        Transaction tx = gigaSpace.getCurrentTransaction();

        try {
            //Adding current time to the parameter, to enable multiple times calling job with same parameters
            long currentTimeInMillis = System.currentTimeMillis();
            JobParameter currentTimeInMillinsParam = new JobParameter(currentTimeInMillis);

            Map parameterMap = new LinkedHashMap();
            addDirectoryParams(valuationSliceRun, parameterMap);

            parameterMap.put(CURRENT_TIME, currentTimeInMillinsParam);

            JobParameters paramMap = new JobParameters(parameterMap);
            JobExecution cmExecution = launchJobWithParameters(paramMap);
            for (Throwable t : cmExecution.getAllFailureExceptions()) {
                throw new RuntimeException(t);
            }
        } catch (Exception e) {
            throw new RuntimeException("Exception during batch job", e);
        } finally {
            repositoryFactoryBean.clear();
        }

    }

    private JobExecution launchJobWithParameters(JobParameters paramMap) throws Exception {
        return jobLauncher.run(cmJob, paramMap);
    }
}

从另一个类调用过程方法,如下所示

public class FileBasedProcessingEventListener implements ApplicationContextAware {
    @Value("${feeddownload.basedir}")
    private String baseDir;

    @Autowired
    private BasicFileProcessor cmProcessor;

    @Autowired
    private FileBasedProcessingExceptionHandler fileBasedProcessingExceptionHandler;


    public void handle(FileBasedProcessingEvent fileBasedProcessingEvent, GigaSpace gigaSpace) throws IOException {
        LOGGER.info("Processing file based processing event : " + fileBasedProcessingEvent);
        createLockFiles(fileBasedProcessingEvent);
        handleEvent(fileBasedProcessingEvent, gigaSpace);
    }

    private void handleEvent(FileBasedProcessingEvent fileBasedProcessingEvent, GigaSpace gigaSpace) {
        Transaction tx = gigaSpace.getCurrentTransaction();

        cmProcessor.process(fileBasedProcessingEvent.getRiskRunCompletion(), versionedSliceName, gigaSpace);


    }

}

从框架中调用句柄方法。现在我不知道为什么我得到如下的例外

Caused by: org.springframework.transaction.InvalidIsolationLevelException: Jini Transaction Manager does not support serializable isolation level
    at org.openspaces.core.transaction.manager.AbstractJiniTransactionManager.applyIsolationLevel(AbstractJiniTransactionManager.java:271)
    at org.openspaces.core.transaction.manager.AbstractJiniTransactionManager.doJiniBegin(AbstractJiniTransactionManager.java:251)
    at org.openspaces.core.transaction.manager.AbstractJiniTransactionManager.doBegin(AbstractJiniTransactionManager.java:207)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:372)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:417)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:255)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

没有一个类被标记为事务性的,我不确定为什么在我没有将任何类或任何方法标记为事务时调用TransactionInterceptor它不应该有任何问题。我还使用了Transaction tx = gigaSpace.getCurrentTransaction();要检查该事务是否处于活动状态,它仅为空

当所有类都没有标记为事务时,我很困惑为什么spring试图在事务下调用此方法

2 个答案:

答案 0 :(得分:0)

看起来Gigaspaces事务管理器基于Spring事务管理基础结构,可以从文档here中推断出来 - 所以如果您使用的是Gigaspaces事务API,那么您正在使用Spring事务管理。另外值得一看的是xml配置文件中的任何事务管理器配置,它将指向确切的事务管理器类。

答案 1 :(得分:0)

确实看来交易正在使用中,检查你是否在pu.xml中定义了一个事务管理器,特别是检查jobLauncher初始化。