Updates for GraalVM
This commit updates all places where Spring Batch uses an @Configuration annotation to no proxy bean methods. This is needed for GraalVM support.
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
744d1834fe
commit
b708dfb025
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.annotation;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.core.configuration.JobRegistry;
|
||||
import org.springframework.batch.core.configuration.support.MapJobRegistry;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
@@ -22,6 +26,7 @@ import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.scope.JobScope;
|
||||
import org.springframework.batch.core.scope.StepScope;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -32,9 +37,6 @@ import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Base {@code Configuration} class providing common structure for enabling and using Spring Batch. Customization is
|
||||
* available by implementing the {@link BatchConfigurer} interface. {@link BatchConfigurer}.
|
||||
@@ -45,23 +47,29 @@ import java.util.Collection;
|
||||
* @since 2.2
|
||||
* @see EnableBatchProcessing
|
||||
*/
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import(ScopeConfiguration.class)
|
||||
public abstract class AbstractBatchConfiguration implements ImportAware {
|
||||
public abstract class AbstractBatchConfiguration implements ImportAware, InitializingBean {
|
||||
|
||||
@Autowired(required = false)
|
||||
private DataSource dataSource;
|
||||
|
||||
private BatchConfigurer configurer;
|
||||
|
||||
private JobRegistry jobRegistry = new MapJobRegistry();
|
||||
|
||||
private JobBuilderFactory jobBuilderFactory;
|
||||
|
||||
private StepBuilderFactory stepBuilderFactory;
|
||||
|
||||
@Bean
|
||||
public JobBuilderFactory jobBuilders() throws Exception {
|
||||
return new JobBuilderFactory(jobRepository());
|
||||
return this.jobBuilderFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StepBuilderFactory stepBuilders() throws Exception {
|
||||
return new StepBuilderFactory(jobRepository(), transactionManager());
|
||||
return this.stepBuilderFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -75,7 +83,7 @@ public abstract class AbstractBatchConfiguration implements ImportAware {
|
||||
|
||||
@Bean
|
||||
public JobRegistry jobRegistry() throws Exception {
|
||||
return new MapJobRegistry();
|
||||
return this.jobRegistry;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -89,6 +97,12 @@ public abstract class AbstractBatchConfiguration implements ImportAware {
|
||||
"@EnableBatchProcessing is not present on importing class " + importMetadata.getClassName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
this.jobBuilderFactory = new JobBuilderFactory(jobRepository());
|
||||
this.stepBuilderFactory = new StepBuilderFactory(jobRepository(), transactionManager());
|
||||
}
|
||||
|
||||
protected BatchConfigurer getConfigurer(Collection<BatchConfigurer> configurers) throws Exception {
|
||||
if (this.configurer != null) {
|
||||
return this.configurer;
|
||||
@@ -123,21 +137,28 @@ public abstract class AbstractBatchConfiguration implements ImportAware {
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class ScopeConfiguration {
|
||||
|
||||
private static StepScope stepScope;
|
||||
|
||||
private static JobScope jobScope;
|
||||
|
||||
static {
|
||||
jobScope = new JobScope();
|
||||
jobScope.setAutoProxy(false);
|
||||
|
||||
stepScope = new StepScope();
|
||||
stepScope.setAutoProxy(false);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static StepScope stepScope() {
|
||||
StepScope stepScope = new StepScope();
|
||||
stepScope.setAutoProxy(false);
|
||||
return stepScope;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static JobScope jobScope() {
|
||||
JobScope jobScope = new JobScope();
|
||||
jobScope.setAutoProxy(false);
|
||||
return jobScope;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.annotation;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.batch.core.configuration.support.ApplicationContextFactory;
|
||||
import org.springframework.batch.core.configuration.support.AutomaticJobRegistrar;
|
||||
import org.springframework.batch.core.configuration.support.DefaultJobLoader;
|
||||
@@ -27,8 +29,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Base {@code Configuration} class providing common structure for enabling and using Spring Batch. Customization is
|
||||
* available by implementing the {@link BatchConfigurer} interface.
|
||||
@@ -37,7 +37,7 @@ import java.util.Collection;
|
||||
* @since 2.2
|
||||
* @see EnableBatchProcessing
|
||||
*/
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class ModularBatchConfiguration extends AbstractBatchConfiguration {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.annotation;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.target.AbstractLazyCreationTargetSource;
|
||||
import org.springframework.batch.core.configuration.JobRegistry;
|
||||
@@ -30,8 +33,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* Base {@code Configuration} class providing common structure for enabling and using Spring Batch. Customization is
|
||||
* available by implementing the {@link BatchConfigurer} interface. The main components are created as lazy proxies that
|
||||
@@ -43,7 +44,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
* @since 2.2
|
||||
* @see EnableBatchProcessing
|
||||
*/
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class SimpleBatchConfiguration extends AbstractBatchConfiguration {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.batch.integration.chunk.RemoteChunkingWorkerBuilder;
|
||||
import org.springframework.batch.integration.partition.RemotePartitioningMasterStepBuilderFactory;
|
||||
import org.springframework.batch.integration.partition.RemotePartitioningManagerStepBuilderFactory;
|
||||
import org.springframework.batch.integration.partition.RemotePartitioningWorkerStepBuilderFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -34,8 +35,8 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
* @since 4.1
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
@Configuration
|
||||
public class BatchIntegrationConfiguration {
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class BatchIntegrationConfiguration implements InitializingBean {
|
||||
|
||||
private JobExplorer jobExplorer;
|
||||
|
||||
@@ -43,6 +44,18 @@ public class BatchIntegrationConfiguration {
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
private RemoteChunkingMasterStepBuilderFactory remoteChunkingMasterStepBuilderFactory;
|
||||
|
||||
private RemoteChunkingManagerStepBuilderFactory remoteChunkingManagerStepBuilderFactory;
|
||||
|
||||
private RemoteChunkingWorkerBuilder remoteChunkingWorkerBuilder;
|
||||
|
||||
private RemotePartitioningMasterStepBuilderFactory remotePartitioningMasterStepBuilderFactory;
|
||||
|
||||
private RemotePartitioningManagerStepBuilderFactory remotePartitioningManagerStepBuilderFactory;
|
||||
|
||||
private RemotePartitioningWorkerStepBuilderFactory remotePartitioningWorkerStepBuilderFactory;
|
||||
|
||||
@Autowired
|
||||
public BatchIntegrationConfiguration(
|
||||
JobRepository jobRepository,
|
||||
@@ -57,38 +70,47 @@ public class BatchIntegrationConfiguration {
|
||||
@Deprecated
|
||||
@Bean
|
||||
public RemoteChunkingMasterStepBuilderFactory remoteChunkingMasterStepBuilderFactory() {
|
||||
return new RemoteChunkingMasterStepBuilderFactory(this.jobRepository,
|
||||
this.transactionManager);
|
||||
return this.remoteChunkingMasterStepBuilderFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RemoteChunkingManagerStepBuilderFactory remoteChunkingManagerStepBuilderFactory() {
|
||||
return new RemoteChunkingManagerStepBuilderFactory(this.jobRepository,
|
||||
this.transactionManager);
|
||||
return this.remoteChunkingManagerStepBuilderFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public <I,O> RemoteChunkingWorkerBuilder<I, O> remoteChunkingWorkerBuilder() {
|
||||
return new RemoteChunkingWorkerBuilder<>();
|
||||
return remoteChunkingWorkerBuilder;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Bean
|
||||
public RemotePartitioningMasterStepBuilderFactory remotePartitioningMasterStepBuilderFactory() {
|
||||
return new RemotePartitioningMasterStepBuilderFactory(this.jobRepository,
|
||||
this.jobExplorer, this.transactionManager);
|
||||
return remotePartitioningMasterStepBuilderFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RemotePartitioningManagerStepBuilderFactory remotePartitioningManagerStepBuilderFactory() {
|
||||
return new RemotePartitioningManagerStepBuilderFactory(this.jobRepository,
|
||||
this.jobExplorer, this.transactionManager);
|
||||
return this.remotePartitioningManagerStepBuilderFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RemotePartitioningWorkerStepBuilderFactory remotePartitioningWorkerStepBuilderFactory() {
|
||||
return new RemotePartitioningWorkerStepBuilderFactory(this.jobRepository,
|
||||
this.jobExplorer, this.transactionManager);
|
||||
return this.remotePartitioningWorkerStepBuilderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
this.remoteChunkingMasterStepBuilderFactory = new RemoteChunkingMasterStepBuilderFactory(this.jobRepository,
|
||||
this.transactionManager);
|
||||
this.remoteChunkingManagerStepBuilderFactory = new RemoteChunkingManagerStepBuilderFactory(this.jobRepository,
|
||||
this.transactionManager);
|
||||
this.remoteChunkingWorkerBuilder = new RemoteChunkingWorkerBuilder<>();
|
||||
this.remotePartitioningMasterStepBuilderFactory = new RemotePartitioningMasterStepBuilderFactory(this.jobRepository,
|
||||
this.jobExplorer, this.transactionManager);
|
||||
this.remotePartitioningManagerStepBuilderFactory = new RemotePartitioningManagerStepBuilderFactory(this.jobRepository,
|
||||
this.jobExplorer, this.transactionManager);
|
||||
this.remotePartitioningWorkerStepBuilderFactory = new RemotePartitioningWorkerStepBuilderFactory(this.jobRepository,
|
||||
this.jobExplorer, this.transactionManager);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user