I have a spring mvc web application with a FormattingConversionServiceFactoryBean registerd in the parent context (spring-application-context.xml).
In my parent context I have a FormattingConversionServiceFactoryBean defined as follows...
@Component("applicationConversionService")
public class ApplicationConversionServiceFactoryBean extends
FormattingConversionServiceFactoryBean {
It is loaded in my parent context as follows...
<context:component-scan base-package="com.myCompany.reporting.converter" />
I use it in my child/servlet context as follows...
<mvc:annotation-driven conversion-service="applicationConversionService"/>
Then in my controllers I can just grab this bean using ...
@Autowired
private ApplicationConversionServiceFactoryBean applicationConversionService;
So far so good.
I now have a case where I want to use this conversion factory service bean in one of my spring batch job beans. The job beans are defined in the spring batch admin console batch jobs override file. I've tried to autowire the conversion service bean from my parent context into my jdbc writer. The compile works in but the autowired conversion service is always null at runtime. Here is how I an autowiring.
public class BulletinBarUpdateItemWriter extends AbstractDao implements ItemWriter<Map<String,String>> {
@Autowired
private ApplicationConversionServiceFactoryBean applicationConversionService;
Has this got something to do with the spring batch admin beans being in a different context as per the way the spring batch admin servlet is defined in my web.xml? See below ....
<servlet>
<servlet-name>Batch Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml,
classpath*:/org/springframework/batch/admin/web/resources/webapp-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
What is the right way to get access to the conversionService bean in my spring batch job beans? I want to use it in my spring batch job beansthe same way that I do in my controllers.
As mentioned earlier my Jdbc writer bean is defined in a job.xml file inside the spring batch admin batch jobs directory as per below.
<bean id="bulletinBarUpdateItemWriter"
class="com.mycompany.reporting.dao.itemwriter.BulletinBarUpdateItemWriter"
parent="abstractCustDbJdbcDao"/>