Replies: 5 comments 2 replies
-
Thank you for opening this discussion. Please share the complete code example that you are trying to modularize with |
Beta Was this translation helpful? Give feedback.
-
I want to migrate my legacy application to spring boot and use JavaConfig instead of xml. <?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byName"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/batch
https://www.springframework.org/schema/batch/spring-batch.xsd">
<bean id="batchTaskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" c:threadNamePrefix="batch-"/>
<batch:job-repository />
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher" p:taskExecutor-ref="batchTaskExecutor"/>
<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"/>
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator"/>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>
<bean id="stepRegistry" class="org.springframework.batch.core.configuration.support.MapStepRegistry"/>
<bean id="jobLoader" class="org.springframework.batch.core.configuration.support.DefaultJobLoader"/>
<bean id="automaticJobRegistrar" class="org.springframework.batch.core.configuration.support.AutomaticJobRegistrar">
<property name="applicationContextFactories">
<bean class="org.springframework.batch.core.configuration.support.ClasspathXmlApplicationContextsFactoryBean">
<property name="resources" value="${jobRegistrar.resources:classpath*:resources/batch/*.xml}" />
</bean>
</property>
</bean>
</beans> |
Beta Was this translation helpful? Give feedback.
-
How is that related to @Bean
public ClasspathXmlApplicationContextsFactoryBean classpathXmlApplicationContextsFactoryBean(@Value("${jobRegistrar.resources:classpath*:resources/batch/*.xml}") Resource[] resources){
ClasspathXmlApplicationContextsFactoryBean factoryBean = new ClasspathXmlApplicationContextsFactoryBean();
factoryBean.setResources(resources);
return factoryBean;
}
@Bean
public AutomaticJobRegistrar automaticJobRegistrar(ClasspathXmlApplicationContextsFactoryBean factoryBean) throws Exception {
AutomaticJobRegistrar registrar = new AutomaticJobRegistrar();
registrar.setApplicationContextFactories(factoryBean.getObject());
return registrar;
} My understanding from the Boot discussion is that you are using |
Beta Was this translation helpful? Give feedback.
-
I am not suggesting to use child contexts, what I am suggesting is to convert the XML configuration you shared in Java. Basically translating the 9 XML bean definitions into 9 bean definitions in Java. That's it. Apologies for the confusion. Now the fact that one of the beans (the Please let me know if you need more support on this, I would be happy to help. Otherwise, please close the discussion. Thank you. |
Beta Was this translation helpful? Give feedback.
-
I reviewed your PR. The change you are suggesting in that PR is to make Spring Boot add a
What I understood from your initial request against Boot is to add support for modularized configs in Boot itself (ie writing the equivalent code currently in Batch with context hierarchies, etc but in Boot), which I discourage. But now after discussing with you what you are looking for (ie translating an XML config into a Java config for a Moreover, I would personally recommend modulazing configs by having a single Batch job per Boot app, rather than relying on a "feature" of Spring Batch or Spring Boot. This architecture removes a whole category of problems (naming clashes, job-scoped beans, etc) by design. This approach is also inline with Spring Boot 3, see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#multiple-batch-jobs. I am closing this ticket for now as I believe I answered your question, but feel free to add a comment if you still need help on this. |
Beta Was this translation helpful? Give feedback.
-
Original issue: spring-projects/spring-boot#36202 (comment)
Beta Was this translation helpful? Give feedback.
All reactions