spring-batch,springjunit4classrunner , Failed to load ApplicationContext: Spring and junit


Failed to load ApplicationContext: Spring and junit

Question:

Tag: spring-batch,springjunit4classrunner

I'm writing unit tests for a Spring application. I have put my SpringContext.xml in pe.edu.upc.demo.configuration.

SpringContext.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/jpa 
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> 

<jpa:repositories base-package="pe.edu.upc" />

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost/matricula" />
    <property name="username" value="root" />
    <property name="password" value="root" />
</bean>

<bean id="jpaVendorAdapter"
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="showSql" value="true" />
    <property name="generateDdl" value="true" />
    <property name="database" value="MYSQL" />
</bean>

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
    <!-- spring based scanning for entity classes -->
    <property name="packagesToScan" value="pe.edu.upc" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" />

<!-- For consider the using of annotations foe defining Spring Bean -->
<context:annotation-config />

<!-- For defining Spring Bean -->
<context:component-scan base-package="pe.edu.upc"></context:component-scan>


<bean id="jdbTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource" />
</bean>

As you can see, the SpringContext.xml is located in src/main/java/pe/edu/upc/demo/configuration. I'm programming in Netbeans. I'm wondering if this path is the correct.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"file:src/main/java//pe/edu/upc/demo/configuration/SpringContext.xml"})
public class CursoTest {


@Autowired
private CursoRepository cursoRepository;

@Test
public void prueba(){

    try {

        Curso curso = new Curso();
        curso.setNombre("Pruebas de Software");
        cursoRepository.save(curso);

        List<Curso> lista = cursoRepository.findAll();
        System.out.println("Lista de Cursos");
        for (Curso c : lista) {
            System.out.println(" Curso Id " + c.getIdcurso());
            System.out.println(" Nombre " + c.getNombre());
            System.out.println(" #Creditos " + c.getCreditos());
        }


    } catch (Exception e) {
       e.printStackTrace();

    }
}

}

After , I run the test of the "CursoTest", I get this trace :

Failed to load ApplicationContext
java.lang.IllegalStateException
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
    at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:326)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:212)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    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:483)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alumnoService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private pe.edu.upc.demo.repository.AlumnoRepository pe.edu.upc.demo.service.impl.AlumnoServiceImpl.alumnoRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alumnoRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List pe.edu.upc.demo.repository.AlumnoRepository.findByCursoList() throws java.lang.Exception!
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:121)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
    ... 31 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private pe.edu.upc.demo.repository.AlumnoRepository pe.edu.upc.demo.service.impl.AlumnoServiceImpl.alumnoRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alumnoRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List pe.edu.upc.demo.repository.AlumnoRepository.findByCursoList() throws java.lang.Exception!
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
    ... 47 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alumnoRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List pe.edu.upc.demo.repository.AlumnoRepository.findByCursoList() throws java.lang.Exception!
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:151)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:252)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1014)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
    ... 49 more
Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List pe.edu.upc.demo.repository.AlumnoRepository.findByCursoList() throws java.lang.Exception!
    at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:97)
    at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.java:66)
    at org.springframework.data.jpa.repository.query.SimpleJpaQuery.fromQueryAnnotation(SimpleJpaQuery.java:169)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:114)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:160)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:68)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:304)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:161)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:162)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:44)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:144)
    ... 57 more
Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: alumnoList of: pe.edu.upc.demo.domain.Alumno [From pe.edu.upc.demo.domain.Alumno a inner join fetch a.alumnoList]
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1374)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:294)
    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:483)
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:334)
    at com.sun.proxy.$Proxy32.createQuery(Unknown Source)
    at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:91)
    ... 67 more
Caused by: org.hibernate.QueryException: could not resolve property: alumnoList of: pe.edu.upc.demo.domain.Alumno [From pe.edu.upc.demo.domain.Alumno a inner join fetch a.alumnoList]
    at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:83)
    at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:77)
    at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1967)
    at org.hibernate.hql.internal.ast.tree.FromElementType.getPropertyType(FromElementType.java:313)
    at org.hibernate.hql.internal.ast.tree.FromElement.getPropertyType(FromElement.java:490)
    at org.hibernate.hql.internal.ast.tree.DotNode.getDataType(DotNode.java:616)
    at org.hibernate.hql.internal.ast.tree.DotNode.prepareLhs(DotNode.java:267)
    at org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:214)
    at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:119)
    at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:377)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3645)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3431)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3309)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:562)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:250)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
    at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
    at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:222)
    at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:200)
    at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1703)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291)
    ... 74 more

Answer:

It looks like there's a problem in your hibernate query or mapping:

Caused by: org.hibernate.QueryException: could not resolve property:
alumnoList of: pe.edu.upc.demo.domain.Alumno 
[From pe.edu.upc.demo.domain.Alumno a inner join fetch a.alumnoList]

Related:


To read Excel can we use Spring batch?


database,excel,spring-batch
I want to know if it is possible to use Spring Batch, in order to read from an file Excel and save it in Database. remark : the content of file Excel chang every 2 hours. And if it is not possible with Spring Batch, what other solution can i...

Parallel job execution by setting job module count in Spring XD?


spring-batch,spring-xd
Since besides stream module, Spring-XD slap support to set module count number for batch jobs. For example, module.myjob.count=3. What will happen if the job is deployed in this way? Will the job be deployed on 3 different containers? Will the 3 copies of deployment execute in parallel? Does each copy...

log4j2.xml loaded but not applied [JVM argument]


java,xml,spring,spring-boot,spring-batch
I am trying to create a batch using spring batch, spring mvc and spring boot. And I am using log4j2 for logging. My goal is to load an external log4j2.xml configuration file thanks to JVM arguments like that -Dlog4j.configurationFile=file://C:\{path}\Workspace\demo-indexeur\config\log4j2.xml Spring boot detect my file (I have no error in the...

How to show sum of transaction amounts and count in a header tag in an output xml generated in Spring batch?


java,spring,spring-batch
I need to create a xml file from some tables (some transactions) using Spring Batch. I need to add a header to the xml containing the sum of total transaction amount and a few details which needs some data that is calculated during processing in batch. I know header could...

Could not autowired Object in ItemStreamReader open method


java,spring,spring-batch,reader
I use Spring Batch with Spring Boot and here is a my main class. @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } Here is my configuration classes @Configuration public class AppConfig { @Bean public MyObject getObject() { return new MyObject(); } } @Configuration...

Spring Batch | MongoItemReader | How to pass JobParameters to mongo query?


spring-batch
How can I pass JobParameters to MongoItemReader query ? My ItemReader looks like :- @Bean public ItemReader<Person> PersonTenantBasedItemReader() { MongoItemReader<Person> reader = new MongoItemReader<Person>(); reader.setTemplate(mongoTemplate); reader.setTargetType((Class<? extends Person>) Person.class); reader.setQuery("{status:'XYZ',nextCheckpointDate:{$gte:?fromDate,$lte:?toDate}"); // !!!!I want to pass fromDate and toDate as job parameters. !!!! Map<String, Direction> sorts = new HashMap<String,...

Triggering spark jobs with REST


rest,apache-spark,spring-batch,job-scheduling,spring-data-hadoop
I have been of late trying out apache spark. My question is more specific to trigger spark jobs. Here I had posted question on understanding spark jobs. After getting dirty on jobs I moved on to my requirement. I have a REST end point where I expose API to trigger...

Spring batch FileItemWriter not creating file at correct path


java,linux,spring,websphere,spring-batch
I have a spring batch service containing a FileItemReader,FileItemProcessor and FileItemWriter.When creating the FileItemWriter I have to set the Resource that will be my output file. I am running the batch service on websphere on a Linux machine.The problem is if I set the resource as new FileSystemResource(new File("opt\temp1\myFile.txt")), the...

Logs are not printing


java,log4j,springjunit4classrunner
I am currently working on a project which has spring used in it. For Junit, i am using @RunWith(SpringJUnit4ClassRunner.class) annotation. Everything is working fine except I do not see any logs for spring processing of applicationContext. In the console window, this is a current message : log4j:WARN No appenders could...

How to call a specific method of a tasklet


spring-batch
In a job context there are an 'method' parameter so a could call directly an tasklet method as said in the documentation "If the tasklet is specified as a bean definition, then a method can be specified and a POJO will be adapted to the Tasklet interface. The method suggested...

How to create Master Job to process multiple spring batch job?


java,spring,spring-batch
We have multiple spring batch job.But Each of them needs to be started individually. Is there any way to create a Master Job or any controller in spring which will be responsible for executing all other batch jobs? So that we just have to execute the master job only,and all...

Spring Batch Execution Status Backed by Database


spring-batch,spring-jdbc
From the Spring Guides: For starters, the @EnableBatchProcessing annotation adds many critical beans that support jobs and saves you a lot of leg work. This example uses a memory-based database (provided by @EnableBatchProcessing), meaning that when it’s done, the data is gone. How can I make the execution state backed...

Setting EXIT_MESSAGE in batch_job_execution


spring-batch,batch-processing
One of the step in my job is having an exception and hence the job is failing with the EXIT_CODE "FAILED". Now I want to set the EXIT_MESSAGE as well, I did the following but the message is not getting set.. Any ideas?? chunkContext.getStepContext().getStepExecution().getJobExecution().setExitStatus(ExitStatus.FAILED); ExitStatus es = jobExecution.getExitStatus(); es =...

Spring batch generating reports


spring-batch
I would like to generate a summary report at the end of my batch execution. For ex: I have an ItemProcessor which receives accountId. for every accountId: get MarketplaceId's for every marketplaceId: call real time availability At the end of batch execution I need to provide a nice summary in...

how to use ExecutorChannel in spring integration?


spring,ftp,spring-batch,spring-integration
Firstly thanks for attention i defined ExecutorChannel and task executor in my spring integration project, for async processing on messages with spring batch, as bellow : <bean id="ftpSessionFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory"> <property name="host" value="${ftp.server.ip}"/> <property name="port" value="${ftp.port}"/> <property name="username" value="${ftp.username}"/> <property name="password" value="${ftp.password}"/> <property name="clientMode"...

Spring batch diffrence between Multithreading vs partitioning


multithreading,spring,spring-batch
I cannot understand the difference between multi-threading and partitioning in Spring batch. the implementation is of course different. In partitioning you need to prepare the partitions then process it. I want to know what is the difference and witch one is more efficient way to process when the bottle neck...

Overwriting spring-boot autoconfiguration


java,spring,spring-boot,spring-batch
I'm a little bit confused with the behaviour of spring-boot when overwriting specific autoconfigurations. I like to partly overwrite the BatchAutoConfiguration, but I guess, my question is not specific to BatchAutoConfiguration. Actually, I just want to "overwrite" two methods of this class: public BatchDatabaseInitializer batchDatabaseInitializer() and public ExitCodeGenerator jobExecutionExitCodeGenerator(). Therefore,...

What is the best approach for loading data from DB by multiple threads


java,multithreading,jdbc,spring-batch,java.util.concurrent
I have some data in database in parent child relation, where my table is actually representing a forest of tree data structure. And the table structure is like: row1 parent: null row2 parent:row1 row3 parent:row2 row4 parent:row1 Now when I am loading this data from DB to my data structure...

how to best approach to use spring batch annotation or xml files ?


spring,spring-batch
firstly, thanks for attention,in my spring batch project defined many jobs , for example: <batch:job id="helloWorldJob1" job-repository="jobRepository"> <batch:step id="step1" > <batch:tasklet> <batch:chunk reader="itemReader1" writer="itemWriter1" processor="itemProcessor1"> </batch:chunk> </batch:tasklet> </batch:step> </batch:job> <batch:job id="helloWorldJob2" job-repository="jobRepository"> <batch:step id="step1" > <batch:tasklet> <batch:chunk...

Running a specific spring batch job amongst several jobs contained withing a spring boot fat jar


java,jar,spring-boot,spring-batch
I am trying to run a spring batch job from a spring boot fat jar and I am having issues referencing the nested jars. Here is the command I use: java -cp bignibou-batch-core/build/libs/bignibou-batch-core.jar:lib/spring-batch-core-3.0.3.RELEASE.jar org.springframework.batch.core.launch.support.CommandLineJobRunner com.bignibou.batch.configuration.BatchConfiguration mailingJob Notice how I reference the nested spring batch jar using the colon. Why is...

combine spring batch and spring integration?


spring,ftp,spring-batch,spring-integration
thanks for attention,i defined a combine spring batch and spring integration project and communicate with ftp server to retrieve file and process on it and write on ftp, i am looking for a good architecture for my project, i designed an architecture with spring integration as bellow diagram: when retrieve...

Exclusive batch jobs with javax.batch/jsr352


java,quartz-scheduler,spring-batch,javax.batch,jsr352
We have an application which does a lot of imports and exports - basically between CSV files and database tables. Some of the imports and exports are conflicting (you can't execute them simultaneously) for various reasons (like "legacy code"). We were looking into javax.batch. Conceptually it suits very well. But...

@BeforeStep annotated method not being called


spring-batch
I am writing a spring batch job. But when this Archive class which implenets the tasklet interface in loaded, the method under the annotation @BeforeStep is not being called. Can anyone help me with this ? Thank You import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardCopyOption;...

Spring Batch reader file by file


spring,mongodb,spring-batch
I'm developing a Spring webapp, using spring boot and spring batch frameworks. We have a set of complex & different json files, and we need to: read each file slightly modify its content finally store them in mongodb. The question: It makes sense to use spring batch for this task?...

Spring GS - Creating a Batch Service missing output from db query


spring-batch
I have run the complete source for Getting Started - Creating a Batch Service Knowing that the sample uses the memory-based database provided by the @EnableBatchProcessing, is the db query result expected or it will only be available if data will be persisted permanently? After adding some debug lines, it...

Spring Batch - Skip Record On Process


spring-batch
I wanted to skip some record on process. what i have tried is, i have created custom exception and throw the exception when i want to skip the record and its calling the Skip listener onSkipInProcess method.Its working fine. please find the configuration. <batch:chunk reader="masterFileItemReader" writer="masterFileWriter" processor="itemProcessor" commit-interval="5000" skip-limit="100000" >...

WriterNotOpenException when using StepScope annotation in Spring Batch


parameters,spring-batch,writer
I have a custom writer which works well ; however, I'd like to set the name of my output file through JobParameters instead of using a fixed string in my configuration. In order to do that, I added the @StepScope annotation and parameters, just like I did with my ItemReader....

Spring Batch Add Custom Fields


spring,spring-batch,batch-processing
I've never used Spring Batch before but it seems like a viable option for what I am attempting to accomplish. I have about 15 CSV files for 10 institutions that I need to process nightly. I am stashing the CSV into staging tables in an Oracle database. The CSV File...

How does Spring Batch manage transactions (with possibly multiple datasources)?


java,transactions,spring-batch
I would like some information about the data flow in a Spring Batch processing but fail to find what I am looking for on the Internet (despite some useful questions on this site). I am trying to establish standards to use Spring Batch in our company and we are wondering...

Access @JobScope bean in spring batch with partitioned step


spring,spring-batch
Is there a way to access bean which is defined as @JobScope in partitioned step? We defined http client bean as @JobScope since it is unique per job but dynamically created and we need it in slave steps to issue post requests. When we autowire everything we get Error creating...

Change Spring Boot project to inherit custom dependency management


java,spring,maven,spring-boot,spring-batch
I have a small Spring Boot application which I must adapt to use a custom parent. Google finds lots of examples of how to migrate to Spring Boot, but I am at a loss as to migrate from Spring Boot (which I barely know to begin with). The reasons To...

FlatFileParseException Spring batch


spring-batch,filereader
I am getting flat file parse exception when i use FlatFileItemReader in my job configuration. Actually it was working fine, but with recent files its throwing error. org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 1 in resource=[URL [file:/prod/users/cdi/crh537/Java_All/input/xaaaaa]], input=[16910203315393417SEVAN Q DANG18711 PARK GROVE [email protected]MAR CL197311192013042504Closed (zero balance DDA)220PUSA] The main difference is...

Removing duplicate code from Spring job configuration


java,spring,spring-batch
Below is my step configuration - <beans:bean id="myInputFileReader" class="com.rbos.fm.risk.batch.spring.reader.InputFileReader" scope="step"> <beans:property name="delegate"> <beans:bean class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> <beans:property name="resource" ref="inputFileSystemResource" /> <beans:property name="linesToSkip" value="1" /> <beans:property name="lineMapper"> <beans:bean...

how to run asynchronous queries with Spring


spring,cassandra,spring-batch
I need to use asynchronous queries using Spring framework. I use Cassandra and Java driver from Datastax. How can call the executeAsync method and get the results.

The import org.springframework.test.context.junit4.SpringJUnit4ClassRunner cannot be resolved


java,spring,maven,spring-mvc,springjunit4classrunner
I'm a newbie at Spring and this is also my very first question in StackOverflow so I'm going to try to make this as understandable as possible. I'm trying to make a web service client using Spring and Maven on this tutorial: http://spring.io/guides/gs/consuming-web-service/ and I get this error: The import...

How to set property using “tasklet ref” tag


spring,spring-batch
I have a tasklet ValidarSituacaoTasklet that has an property situacao. This tasklet is used in 2 steps in distinct values for situacao. I declared steps as like: and the bean: <bean id="validarSituacaoTasklet" class="my.package.tasklet.ValidarSituacaoTasklet" scope="step"> </bean> I have to pass 'situacao' to tasklet . I tried: <step id="validaSituacaoStep"> <tasklet ref="validarSituacaoTasklet ">...

Execute database operations inside a chunck orientad step


spring-batch
I have a chunk oriented processor in the form "reader / processor / writer" called Job1. I have to execute database EJB operations after this job ends, if possible, in the same transaction. I have others jobs (implemented by Tasklets) that I could do this in a simply manner. I...

More than one tasklet in a step?


spring,spring-batch,tasklet
I have a tasklet setting some information into my JobContext, and another one checking some stuff to know if I can execute the next steps in my batch or not. Both tasklets work well if I use two different steps in my job flow, but I'd like to use these...

How do I use JdbcPagingItemReader in Spring Batch when my primary key is a string?


java,spring-batch,spring-jdbc
I've got some SQL data that I need to access with an ItemReader in Spring Batch. I thought that JdbcPagingItemReader / PagingQueryProvider would be the perfect fit. The table I'm selecting from has a primary key that is a composite of three columns: INTEGER, VARCHAR, and VARCHAR. And actually, for...

Spring batch - ItemReader within another itemreader or Itemprocessor


spring,spring-batch
Here is my requirement : Create a batch job that 1. Fetches discount programs from Discount table for specific search critieria 2. For each discount program fetched in Step1, Get sales records for sales that fit the discount program dates Get additional details for sales from some other tables 3....

spring integration vs spring batch [on hold]


spring-batch,spring-integration
We have application where we are receiving file every day and it needs to be parsed and persist in db. File has 5000 record. Should we use spring batch or spring integration? And why? we do need to skip bad record and audit them....

How to initialize custom ItemReader?


spring,spring-batch
I have created my custom ItemReader: @Component("pricereader") public class MyItemReader implements ItemReader<Price>{ @Override public Price read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { // TODO Auto-generated method stub return null; } } Calling it in a job thus defined: <batch:job id="job1"> <batch:step id="step1"> <batch:tasklet> <batch:chunk reader="pricereader" processor="priceprocessor" writer="pricewriter" commit-interval="1"/> </batch:tasklet>...

Spring batch for rules


spring,spring-batch
I am new to Spring Batch. I need to run a nightly batch process that: reads records from table A, for each record in table A, run about 10 business rules with logic involve reading data from the database (in each rule) and write into table B in each rule,...

Spring Batch - Write multiple files based on records count


java,spring,spring-batch
In spring batch, I have an requirement to read from the database and to write in a file, The no of rows allowed in a file is N, so if N+10 records are fetched then two files should be created containing N rows and 10 rows respectively. Can someone please...

Spring Batch Item Reader is executing only once


java,spring,spring-batch
Trying to implement Spring batch,but facing a strange problem,Our ItemReader class is executing only once. Here below is the detail. If we have 1000 rows in DB. Our Item reader fetch 1000 rows from DB,and pass list to ItemWriter ItemWriter successfully delete all items. Now ItemReader again tries to fetch...

how to run async batch job in batch-int:job-launching-gateway?


spring,spring-batch,spring-integration
Firstly thanks for attention, I combined spring integration and spring batch in my project, i want to launch jobs in asynchronous mode in batch-int:job-launching-gateway, my means is that each message in input channel launch job in asynchronous and not wait util to complete the jobs,my code is: <batch-int:job-launching-gateway request-channel="outboundJobRequestChannel" reply-channel="jobLaunchReplyChannel"/>...

disable @EnableScheduling on spring tests


spring,unit-testing,junit,junit4,springjunit4classrunner
When I run my unit tests and it invokes my scheduled tasks - I dont want it to do this. It is because I have @EnableScheduling on my main app configuration. How can I disable this on my unit tests? I have come across this question/answer which suggests setting up...

Batch job initialization fails on error while creating bean with name 'batchPropertyPostProcessor'


java,spring-batch,jsr352
I'm trying to implement sample batch application using JSR-352 API and Spring Batch 3.0.4 as implementation. Batch job execution fails during initialization phase on error while creating bean with name 'batchPropertyPostProcessor': Exception in thread "main" javax.batch.operations.JobStartException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchPropertyPostProcessor': Injection of autowired dependencies failed; nested exception...

“Address already in use: bind” exception when running Gradle JUnit tests


gradle,spring-boot,junit4,properties-file,springjunit4classrunner
I'm using Spring Boot 1.2.2.RELEASE, JUnit4, and Gradle 2.1 for a RESTful service and am trying to define a properties file which includes and/or overrides values which will be used in JUnit tests only. All tests execute without an issue when invoked as a JUnit test. However, when these same...

Spring Batch : custom ItemReader


java,spring,spring-batch
I have a Spring Batch project with a simple custom reader and writer. When i run the code i end up with an endeless loop printing the first item "item 1". What am i doing wrong? Here is my code: Reader.java public class Reader implements ItemReader<SimpleItem> { public SimpleItem read()...