Hello everybody,
First of all, let me introduce myself as it is my first post here. I'm Patrick, working for an insurance company as software developer. I lately was involved in a project for migrating some COBOL application into java. This migration needs to be a functional copy of the previous application without any changes and deserve only a technical purpose : we soon won't have any competency left for COBOL.
That being said, as you probably know, COBOL applications were really much focuses on jobs, steps, in a word "batchs". Then... well... I need to have somehow a way of making java batchs. Quick look on internet, guess what, Spring batch seems to be great for it as I would need to handle transactions to ensure either the complete batch succeed or nothing is done, restarting / stopping batchs, monitoring, ...
Now, I am JSF / JAX-WS developer with application layer done through JPA / hibernate, EJB3... but never touched to the Spring Framework.
I tried to work with the documentation at this address, but I cannot find much information focused on installation. The concepts are rather focused to the batch possibilities.
As a humble beginning, I'd like just to run a first batch, calling nothing more than a small Reader / Writer. I do have an EJB Eclipse project called testbatch, which has an EJB source folder called ejbModule. In it, just a simple package test.batch containing these files :
TestReader.java :
TestWriter.java :Code:public class TestReader implements ItemReader<String> { static String[] strings = {"test1", "test2", "test3", "test4"}; static Integer index = 0; @Override public String read() throws Exception, UnexpectedInputException, ParseException { if(index <= 3){ String s = strings[index]; index++; return s; } return null; } }
batch-sample-context.xml :Code:public class TestWriter implements ItemWriter<String> { @Override public void write(List<? extends String> items) throws Exception { for(String s: items) System.out.println(s); } }
I found samples of these simple calls at this address (sorry it's in french).Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="TestReader" class="test.batch.TestReader" /> <bean id="TestWriter" class="test.batch.TestWriter" /> <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> <property name="jobRepository" ref="jobRepository" /> </bean> <bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"> <property name="transactionManager" ref="transactionManager" /> </bean> <bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" > </bean> <bean id="minimal" class="org.springframework.batch.core.job.SimpleJob"> <property name="jobRepository" ref="jobRepository" /> <property name="steps"> <bean id="simpleStep" class="org.springframework.batch.core.step.item.SimpleStepFactoryBean"> <property name="transactionManager" ref="transactionManager" /> <property name="jobRepository" ref="jobRepository" /> <property name="itemReader" ref="TestReader" /> <property name="itemWriter" ref="TestWriter" /> </bean> </property> </bean> </beans>
When I make a configuration in Eclipse withas main class andCode:org.springframework.batch.core.launch.support.CommandLineJobRunneras program arguments, I always receive this error :Code:batch-sample-context.xml minimal
Whatever I'm trying, I just cannot have log4j be configured properly. I found on internet I should try something like adding this to my batch xml file :Code:log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext). log4j:WARN Please initialize the log4j system properly.
I tried it with this xml :Code:<bean id="log4jInitialisation" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetClass" value="org.springframework.util.Log4jConfigurer" /> <property name="targetMethod" value="initLogging" /> <property name="arguments"> <list> <value>ejbModule/test/batch/log4j.xml</value> </list> </property> </bean>
but wasn't able to make it work.Code:<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="console" class="org.apache.log4j.ConsoleAppender"> <param name="Target" value="System.out"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/> </layout> </appender> <root> <priority value ="debug" /> <appender-ref ref="console" /> </root> </log4j:configuration>
This example is really stupid, but making a few Hello World to just install the environment is already a big part of the deal.
Do you have advices to make my stupid test work ?
Here it is my first test, which I couldn't make work, but it will eventually be for calling EJB's of my application layer embedded in the JBoss 5.1 Application Server, with transaction management,.... If there exist some good installation guides on Spring Batch, I would fairly appreciate as I could not find anything on this topic in the official documentation.
Another additional point : do I need to jump into Spring Framework to understand how to configure and develop with the Spring Batch facilities ?
Thank you in advance for your advices... integration of new libraries / frameworks are not easy in the Java world, but I hardly found so few documentation for an easy and just simple beginning. I found much, I tested much, I wasn't able to make a single sample work![]()


Reply With Quote
). So you need to put your log4j.properties file into your resources root or alternatively use org.apache.log4j.xml.DOMConfigurator.doConfigure() + XML you provided before creating the Spring context; but as you want to to CommandLineJobRunner that last is not an option for you.