I'm sorry for posting this if it sound stupid, but I am just getting started with spring batch and this issue is driving me nuts.
Let's say my app as 3 jars.
jar1 defines a marshaller interface + impl and has the following context definition:
jar2 injects the marshaller as a resource: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-3.0.xsd"> <bean id="marshaller" class="com.accovia.totem.tjc.MarshallerImpl" /> <bean id="flags" class="com.accovia.totem.tjc.Flags" /> </beans>
and imports in its context like thisCode:public class ToiLineMapper implements LineMapper<InputRecord> { @Resource Marshaller marshaller; ...
Finally my cli-app (using commandlinejobrunner) ties it all up with a app context and a job contextCode:<import resource="classpath*:/applicationContext-totem-infra.xml" />
which does the same import as above and does the standard definitions and has also this to register automatically my jobs:
For reference my reader def (which fails on a NPE on the @resource injection):Code:<!-- Job Registrar --> <bean class="org.springframework.batch.core.configuration.support.AutomaticJobRegistrar"> <property name="applicationContextFactories"> <bean class="org.springframework.batch.core.configuration.support.ClasspathXmlApplicationContextsFactoryBean"> <property name="resources" value="classpath*:/jobs/job*.xml" /> </bean> </property> <property name="jobLoader"> <bean class="org.springframework.batch.core.configuration.support.DefaultJobLoader"> <property name="jobRegistry" ref="jobRegistry" /> </bean> </property> </bean>
For reference my job def:Code:<bean id="toiFileMultiLineItemReader" class="com.accovia.totem.batch.io.MultiLineToiItemReader"> <property name="delegate"> <bean class="org.springframework.batch.item.file.FlatFileItemReader"> <property name="resource" ref="toiFile" /> <property name="lineMapper"> <bean class="com.accovia.totem.batch.io.ToiLineMapper"> </bean> </property> </bean> </property> </bean>
Why is my @Resource always null ?!? Im sure it is something simple and obvious, but I just can't see itCode:<batch:job id="toiJob"> <batch:step id="step"> <batch:tasklet> <batch:chunk reader="toiFileMultiLineItemReader" writer="bookingItemWriter" commit-interval="5" /> </batch:tasklet> </batch:step> </batch:job>
If I Marshaller marshaller = new MarshallerImpl();, the jobs runs perfectly, but it defies the spring use ...
Please help ...
Thanks in advance



Reply With Quote