Я использую Spring batch с весенней загрузкой для обработки моего CSV-файла. Когда я запускаю приложение, я получаю ниже трассировки ошибок.
2018-08-27 16:23:35.694 INFO 12016 --- [nio-9004-exec-1] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: ORACLE
2018-08-27 16:23:36.025 INFO 12016 --- [nio-9004-exec-1] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2018-08-27 16:23:36.898 INFO 12016 --- [nio-9004-exec-1] o.s.b.f.xml.XmlBeanDefinitionReader : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2018-08-27 16:23:36.965 INFO 12016 --- [nio-9004-exec-1] o.s.jdbc.support.SQLErrorCodesFactory : SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
2018-08-27 16:23:37.005 ERROR 12016 --- [nio-9004-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.CannotSerializeTransactionException: PreparedStatementCallback; SQL [INSERT INTO BATCH_JOB_EXECUTION_CONTEXT (SHORT_CONTEXT, SERIALIZED_CONTEXT, JOB_EXECUTION_ID) VALUES(?, ?, ?)]; ORA-08177: can't serialize access for this transaction
; nested exception is java.sql.SQLException: ORA-08177: can't serialize access for this transaction
] with root cause
java.sql.SQLException: ORA-08177: can't serialize access for this transaction
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450) ~[ojdbc7-12.1.0.1.jar!/:12.1.0.1.0]
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399) ~[ojdbc7-12.1.0.1.jar!/:12.1.0.1.0]
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1017) ~[ojdbc7-12.1.0.1.jar!/:12.1.0.1.0]
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:655) ~[ojdbc7-12.1.0.1.jar!/:12.1.0.1.0]
at oracle.jdbc.driver.T4CTTI
После некоторого поиска в Google я обнаружил, что нам нужно создать экземпляр JobRepositoryFactoryBean . поэтому я сделал то же самое в моей BatchConfiguration, как показано ниже.
@Autowired
private DataSource dataSource;
@Autowired
private DataSourceTransactionManager transactionManager;
@Bean
public JobRepositoryFactoryBean jobRepository() throws SQLException{
JobRepositoryFactoryBean factoryBean = new JobRepositoryFactoryBean();
factoryBean.setDatabaseType("ORACLE");
factoryBean.setDataSource(dataSource);
factoryBean.setTransactionManager(transactionManager);
factoryBean.setIsolationLevelForCreate("ISOLATION_READ_UNCOMMITTED");
return factoryBean;
}
И компоненты Datasource ** и ** TransactionManager находятся в моей конфигурации DBConfiguration, как показано ниже.
@Bean
public DataSource dataSource() throws SQLException
{
OracleDataSource dataSource = new OracleDataSource();
dataSource.setUser("xxxxxx");
dataSource.setPassword("xxxxx");
dataSource.setURL("xxxxx");
dataSource.setImplicitCachingEnabled(true);
dataSource.setFastConnectionFailoverEnabled(true);
return dataSource;
}
@Bean(name="transactionManager")
public PlatformTransactionManager transactionManager() throws SQLException{
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(this.dataSource());
return transactionManager;
}
Тогда я получаю ошибку ниже
***************************
APPLICATION FAILED TO START
***************************
Description:
Field transactionManager in com.comcast.FileProcess.configuration.SprintgBatchConfiguration required a bean of type 'org.springframework.jdbc.datasource.DataSourceTransactionManager' that could not be found.
- Bean method 'transactionManager' in 'DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration' not loaded because @ConditionalOnMissingBean (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) found bean 'transactionManager'
Action:
Consider revisiting the conditions above or defining a bean of type 'org.springframework.jdbc.datasource.DataSourceTransactionManager' in your configuration.
Может ли кто-нибудь помочь мне решить эту проблему и запустить мой пакетный процесс.