I've a Spring Batch process with JPA and I have this problem:
I have a class with
#Configuration
public class BeansBatchConfig {
#Bean(name = "jobRepository")
public JobRepositoryFactoryBean jobRepository() {
this.jobRepository = new JobRepositoryFactoryBean();
this.jobRepository.setDataSource(this.dataSource);
this.jobRepository.setTransactionManager(this.transactionManager);
this.jobRepository.setIsolationLevelForCreate(this.isolationLevelForCreate);
return this.jobRepository;
}
The manager:
#Override
public void saveProjectCategory(ProjectCategoryEto eto) {
try {
this.projectCategoryDao.save(getBeanMapper().map(eto, ProjectCategoryEntity.class));
} catch (DataIntegrityViolationException ex) {
this.projectCategoryDao.clear();
LOG.error("Ha habido problemas al insertar el proyecto " + eto.getProject().getCode());
}
}
And the tasklet that call the manager.
The stracktrace:
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:526) ~[spring-orm-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:150) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) ~[spring-batch-infrastructure-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) ~[spring-batch-infrastructure-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:392) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:135) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at com.capgemini.esr2pon.component.daemon.common.utils.ScheduledTasks.launchProjects(ScheduledTasks.java:86) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_80]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_80]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_80]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_80]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_80]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) [na:1.7.0_80]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) [na:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_80]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80]
Caused by: javax.persistence.RollbackException: Transaction marked as rollbackOnly
at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:74) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517) ~[spring-orm-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 32 common frames omitted
I've tried to pue this code in each method but the result is the same
#Transactional(noRollbackFor=EmptyResultDataAccessException .class)
I've think the problem is in the JobRepository but I don't know what I have to change in the Transaction Manager. Any ideas?
Thanks.
UPDATED WITH SAVE METHOD:
#Override
public E save(E entity) {
if (isNew(entity)) {
this.entityManager.persist(entity);
LOG.debug("Saved new {} with id {}.", getEntityName(), entity.getId());
return entity;
} else {
if (this.entityManager.find(entity.getClass(), entity.getId()) != null) {
E update = this.entityManager.merge(entity);
LOG.debug("Updated {} with id {}.", getEntityName(), entity.getId());
return update;
} else {
throw new EntityNotFoundException("Entity not found");
}
}
}
Related
I try to write tests with EasyMock and because I want to mock a static method I want to use PowerMock. When I want to run the test I get a ClassNotFoundException.
This is the test I wrote:
#Test
public void whenCreate_ThenCurrentAccountShouldBeFound() throws Exception {
Account oldAccount = new Account();
oldAccount.setUsername("Test");
oldAccount.setFirstName("FirstName");
oldAccount.setLastName("LastName");
oldAccount.setPassword("Password");
oldAccount.setEmail("maxmusteg#hs-pforzheim.de");
PowerMock.mockStatic(AuthenticationService.class);
PowerMock.expectNew(de.hspf.nxtgenmondial.backend.service.AuthenticationService.getCurrentlyLoggedInUser()).andReturn(oldAccount);
replayAll();
assertEquals("Username name should be Test", "Test", accountService.getCurrentAccount().getUsername());
}
This is the static method:
public static String getCurrentlyLoggedInUser() {
if (SecurityContextHolder.getContext().getAuthentication() != null && SecurityContextHolder.getContext().getAuthentication().getPrincipal() != null) {
if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() instanceof ExtendedUserDetails)
return ((ExtendedUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername();
else
return ((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername();
} else
throw new IllegalStateException("No user logged in");
}
And then there is the getCurrentAccount method:
public Account getCurrentAccount() {
Optional<Account> optionalAccount = accountRepository.findOneByEmail(AuthenticationService.getCurrentlyLoggedInUser());
if (optionalAccount.isPresent())
return optionalAccount.get();
else {
log.warn("Logged in account not found in database");
return null;
}
}
This is the error message that appears. Line 105 is where PowerMock.mockStatic() is called:
org/easymock/internal/MocksControl$MockType
java.lang.NoClassDefFoundError: org/easymock/internal/MocksControl$MockType
at org.powermock.api.easymock.internal.mockstrategy.impl.DefaultMockStrategy.<init>(DefaultMockStrategy.java:8)
at org.powermock.api.easymock.PowerMock.mockStatic(PowerMock.java:287)
at de.hspf.nxtgenmondial.backend.api.account.service.AccountServiceTest.whenCreate_ThenCurrentAccountShouldBeFound(AccountServiceTest.java:105)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:89)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:97)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:127)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.easymock.internal.MocksControl$MockType
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:178)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:70)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 56 more
You are using a version of PowerMock that isn't compatible with your version of EasyMock. From what I see, it is PowerMock that is too old.
I am extending StaxEventItemWriter to write a custom ItemWriter so that I can create the file name dynamically at runtime.
The filename is getting created fine however I am getting below issue when its trying to write the data.
org.springframework.batch.core.step.tasklet.UncheckedTransactionException: java.lang.reflect.InvocationTargetException
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:486)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:272)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
at com.santanderuk.carde.gassaudittransform.GassAuditTransformApplication.main(GassAuditTransformApplication.java:24)
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.batch.item.xml.StaxUtils.getResult(StaxUtils.java:116)
at org.springframework.batch.item.xml.StaxEventItemWriter.createStaxResult(StaxEventItemWriter.java:532)
at org.springframework.batch.item.xml.StaxEventItemWriter.write(StaxEventItemWriter.java:739)
at com.santanderuk.carde.gassaudittransform.writer.IncomeExpenditureStaxWriter.write(IncomeExpenditureStaxWriter.java:67)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:175)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:274)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:199)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
... 20 common frames omitted
Caused by: java.lang.IllegalArgumentException: StAXResult(XMLEventWriter) with XMLEventWriter == null
at javax.xml.transform.stax.StAXResult.<init>(StAXResult.java:90)
at org.springframework.util.xml.StaxUtils.createStaxResult(StaxUtils.java:145)
... 34 common frames omitted
Added below code but its not working.
#Override
public void write(List<? extends Employee> items) throws Exception {
StaxEventItemWriter<AuditRecordsData> xmlFileWriter = new StaxEventItemWriter<>();
xmlFileWriter.setResource(new FileSystemResource(filepath));
xmlFileWriter.setRootTagName("employee");
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
Result res = createStaxResult();
jaxb2Marshaller.setClassesToBeBound(Employee.class);
jaxb2Marshaller.marshal(data, res);
xmlFileWriter.setMarshaller(jaxb2Marshaller);
xmlFileWriter.write(items);
As part of my project requirement I need to pass Collection of objects (List of objects) to oracle stored procedure. And Once I receive the collection object In stored procedure I will do some DB operation using the data. I am getting some issue in java code while setting the argument for stored procedure.
From database side I have created custom type.
create or replace type ESLSolveRequests as Object(latitude Number(38,10),longitude Number(38,10),isExist char(1),rec_id Number,route_cost Number,route_length Number,route_impedance Number);
create or replace type ESLSolveList as table of ESLSolveRequests;
Below are Package and stored procedure
create or replace package PKG_ESL_NSX_Record_Check as
procedure proc_Check_RecordExistance(MAP_IN IN ESLSolveList,MAP_OUT OUT ESLSolveList);
end PKG_ESL_NSX_Record_Check;
create or replace package body PKG_ESL_NSX_Record_Check
as
procedure proc_Check_RecordExistance(MAP_IN IN ESLSolveList,MAP_OUT OUT ESLSolveList)
is
begin
null;
end proc_Check_RecordExistance;
end PKG_ESL_NSX_Record_Check;
Below is java code ,my List List eslSolveRequest is populated with objects, below is my java code
#Repository
public class EslNsxCheckDao extends DatabaseConnection {
private StructDescriptor strDescriptor = null;
private ArrayDescriptor arrayDescriptor = null;
private OracleCallableStatement cStmt = null;
private ARRAY p_message_list = null;
Connection con = null;
public void checkWithNSXDb(List<ESLSolveRequest> eslSolveRequest){
oracle.sql.ARRAY array =null;
try{
Connection con=getJdbcConnection();
this.arrayDescriptor = ArrayDescriptor.createDescriptor("ESLSolveList", con);
this.strDescriptor=StructDescriptor.createDescriptor("ESLSolveRequests",con);
}catch(Exception ex){
}
try {
Object[] param_array=eslSolveRequest.toArray();
p_message_list = new oracle.sql.ARRAY(this.arrayDescriptor, con, param_array);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
this.cStmt =(OracleCallableStatement)conn.prepareCall("{call PKG_ESL_NSX_Record_Check.proc_Check_RecordExistance(:1,:2)}");
this.cStmt.setArray(1, p_message_list);
this.cStmt.registerOutParameter(2,OracleTypes.ARRAY,"ESLSolveList");
this.cStmt.execute();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
I am getting below error
**java.sql.SQLException: Missing descriptor**
at oracle.sql.DatumWithConnection.assertNotNull(DatumWithConnection.java:103)
at oracle.sql.ARRAY.<init>(ARRAY.java:117)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao.checkWithNSXDb(EslNsxCheckDao.java:37)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao$$FastClassBySpringCGLIB$$b62b799d.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao$$EnhancerBySpringCGLIB$$6c531bd5.checkWithNSXDb(<generated>)
at com.comcast.BulkSolveRecordProcess.Batch.Processor.process(Processor.java:28)
at com.comcast.BulkSolveRecordProcess.Batch.Processor.process(Processor.java:12)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:126)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:293)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:192)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:272)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:392)
at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:135)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy75.run(Unknown Source)
at com.comcast.BulkSolveRecordProcess.Events.ScheduledEvents.trigger(ScheduledEvents.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
**java.sql.SQLException: Invalid argument(s) in call
at** oracle.jdbc.driver.OraclePreparedStatement.setARRAYInternal(OraclePreparedStatement.java:6405)
at oracle.jdbc.driver.OraclePreparedStatement.setArrayInternal(OraclePreparedStatement.java:6362)
at oracle.jdbc.driver.OracleCallableStatement.setArray(OracleCallableStatement.java:5682)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setArray(OraclePreparedStatementWrapper.java:121)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao.checkWithNSXDb(EslNsxCheckDao.java:45)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao$$FastClassBySpringCGLIB$$b62b799d.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao$$EnhancerBySpringCGLIB$$6c531bd5.checkWithNSXDb(<generated>)
at com.comcast.BulkSolveRecordProcess.Batch.Processor.process(Processor.java:28)
at com.comcast.BulkSolveRecordProcess.Batch.Processor.process(Processor.java:12)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:126)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:293)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:192)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
Based on what I was reading around and some other similar questions, by specifying a spring batch component being StepScope means that Spring Batch will use the spring container to instantiate a new instance of that component for each step execution.
In my particular case I have the countryXmlFileToDatabaseStep() which configuration is below and another step which just download a file, delete the existing folder and create a new folder with the xml file.
With the current impl I have, without using the #StepScope annotation on the ItemReader everything works fine, but this is not right, as I need the Spring container to instantiate a new instance of the ItemReader component for each step execution. This way I can delete the Xml file from my C:\ProcessFolder and replace it with the new file on the First Step then go to the next step countryXmlFileToDatabaseStep(). If the XML file name will change I can change the name in the properties file which should be picked up by Spring on the next job run.
Currently I am getting a NULL pointer and no idea why. Below is my Step configuration, including the stack trace.
Configuration
#PropertySource("classpath:application.properties")
public class CountriesListJobConfiguration extends AbstractHarvestService {
private static final String QUERY_INSERT_EOI_MASTER= "INSERT " +
"INTO MASTER(ISTER, MVALUE, MCODE, PROFILEURL, TYPE) " +
"VALUES (?, ?, ?, ?, ?)";
#Value( "${path.folder.master.country}" )
private String countryXmlP;
// This points to my drive C:\\ProcessFolder\\Country_20180715.xml
#Bean
#StepScope
ItemReader<CountryName> countryNameItemReader() {
StaxEventItemReader<CountryName> xmlFileReader = new StaxEventItemReader<>();
xmlFileReader.setResource(new FileSystemResource(countryXmlP));
xmlFileReader.setFragmentRootElementName("CountryName");
Jaxb2Marshaller studentMarshaller = new Jaxb2Marshaller();
studentMarshaller.setClassesToBeBound(CountryName.class);
xmlFileReader.setUnmarshaller(studentMarshaller);
return xmlFileReader;
}
#Bean
ItemProcessor<CountryName, CountryName> countryNameItemProcessor() {
return new CountryItemProcessor();
}
#Bean
ItemWriter<CountryName> countryNameItemWriter(DataSource dataSource, NamedParameterJdbcTemplate jdbcTemplate) {
JdbcBatchItemWriter<CountryName> databaseItemWriter = new JdbcBatchItemWriter<>();
databaseItemWriter.setDataSource(dataSource);
databaseItemWriter.setJdbcTemplate(jdbcTemplate);
databaseItemWriter.setSql(QUERY_INSERT_EOI_MASTER);
ItemPreparedStatementSetter<CountryName> studentPreparedStatementSetter = new CountryItemPreparedStatementSetter();
databaseItemWriter.setItemPreparedStatementSetter(studentPreparedStatementSetter);
return databaseItemWriter;
}
#Bean
Step countryXmlFileToDatabaseStep() {
return stepBuilderFactory.get("countryXmlFileToDatabaseStep")
.<CountryName, CountryName>chunk(10)
.reader(countryNameItemReader())
.processor(countryNameItemProcessor())
.writer(countryNameItemWriter(super.dataSource, super.namedParameterJdbcTemplate))
.build();
}
#Bean
public Flow country() {
FlowBuilder<Flow> flowBuilder = new FlowBuilder<>("country");
flowBuilder.start(countryXmlFileToDatabaseStep())
.end();
return flowBuilder.build();
}
The stacktrace:
java.lang.NullPointerException: null
at org.springframework.batch.item.xml.StaxEventItemReader.moveCursorToNextFragment(StaxEventItemReader.java:151) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.item.xml.StaxEventItemReader.doRead(StaxEventItemReader.java:228) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:88) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) ~[spring-aop-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) ~[spring-aop-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) ~[spring-aop-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at com.sun.proxy.$Proxy94.read(Unknown Source) ~[na:na]
at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91) ~[spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:157) ~[spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:116) ~[spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:110) ~[spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69) ~[spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) ~[spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330) ~[spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) ~[spring-tx-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:272) ~[spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81) ~[spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257) ~[spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200) ~[spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) [spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) [spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) [spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) [spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.job.flow.support.state.SplitState$1.call(SplitState.java:93) [spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.batch.core.job.flow.support.state.SplitState$1.call(SplitState.java:90) [spring-batch-core-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_144]
at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_144]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]
I was trying to create a springboot batch job, which has to read data's from a queue, and write into xml format. I am using StaxEventItemWriter for writing , and while running the application I am getting following error. I strongly believe the error is in the itemwriter section, because with the same reader, I am able to write to a flat file using Filefileitemwriter. I am not able to find out what I did wrong. I am really appriciate your help.
[org.springframework.batch.core.step.AbstractStep.execute] Encountered
an error executing step step1 in job importUserJob
org.springframework.batch.item.ItemStreamException: File already
exists: [C:\folder\Sync_0.xml] at
org.springframework.batch.item.util.FileUtils.setUpOutputFile(FileUtils.java:61)
at
org.springframework.batch.item.xml.StaxEventItemWriter.open(StaxEventItemWriter.java:428)
at
org.springframework.batch.item.xml.StaxEventItemWriter.open(StaxEventItemWriter.java:400)
at
org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96)
at
org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310)
at
org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:197)
at
org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at
org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
at
org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at
org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at
org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at
org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)
at
org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
at
org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
at
org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at
org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at
org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy40.run(Unknown Source) at
org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:216)
at
org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:233)
at
org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:125)
at
org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:119)
at
org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:806)
at
org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:790)
at
org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:777)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
Code for itemwriter is provided below.
#Bean
public ItemWriter<WorkerXML> staxEventItemWriter() throws XmlMappingException, Exception{
StaxEventItemWriter<WorkerXML> staxEventItemWriter = new StaxEventItemWriter<WorkerXML>();
try{
XStreamMarshaller marshaller = new XStreamMarshaller();
staxEventItemWriter.setName("StaxEventItemWriter");
staxEventItemWriter.setResource("C://folder//Sync_0.xml"));
staxEventItemWriter.setRootTagName("WorkerXML");
staxEventItemWriter.setOverwriteOutput(false);
staxEventItemWriter.setMarshaller(marshaller);
staxEventItemWriter.setEncoding(StandardCharsets.UTF_8.toString());
staxEventItemWriter.setVersion("XML");//
staxEventItemWriter.setSaveState(true); // staxEventItemWriter.open(new ExecutionContext());
ExecutionContext executionContext = new ExecutionContext();
staxEventItemWriter.open(executionContext);
}
catch(Exception e){
System.out.println("staxEventItemWriter " + e);
}
return staxEventItemWriter;
}
#Bean
public Marshaller marshaller()
{
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(QVCWorkerXML.class);
return marshaller;
}