Skip to content

Commit

Permalink
Updates for GraalVM
Browse files Browse the repository at this point in the history
This commit updates all places where Spring Batch uses an @configuration
annotation to no proxy bean methods. This is needed for GraalVM support.
  • Loading branch information
mminella authored and fmbenhassine committed Sep 8, 2020
1 parent 744d183 commit b708dfb
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
*/
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;
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;
Expand All @@ -32,9 +37,6 @@
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}.
Expand All @@ -45,23 +47,29 @@
* @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
Expand All @@ -75,7 +83,7 @@ public StepBuilderFactory stepBuilders() throws Exception {

@Bean
public JobRegistry jobRegistry() throws Exception {
return new MapJobRegistry();
return this.jobRegistry;
}

@Bean
Expand All @@ -89,6 +97,12 @@ public void setImportMetadata(AnnotationMetadata importMetadata) {
"@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;
Expand Down Expand Up @@ -123,21 +137,28 @@ protected BatchConfigurer getConfigurer(Collection<BatchConfigurer> configurers)
* @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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,8 +29,6 @@
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.
Expand All @@ -37,7 +37,7 @@
* @since 2.2
* @see EnableBatchProcessing
*/
@Configuration
@Configuration(proxyBeanMethods = false)
public class ModularBatchConfiguration extends AbstractBatchConfiguration {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,8 +33,6 @@
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
Expand All @@ -43,7 +44,7 @@
* @since 2.2
* @see EnableBatchProcessing
*/
@Configuration
@Configuration(proxyBeanMethods = false)
public class SimpleBatchConfiguration extends AbstractBatchConfiguration {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -34,15 +35,27 @@
* @since 4.1
* @author Mahmoud Ben Hassine
*/
@Configuration
public class BatchIntegrationConfiguration {
@Configuration(proxyBeanMethods = false)
public class BatchIntegrationConfiguration implements InitializingBean {

private JobExplorer jobExplorer;

private JobRepository jobRepository;

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,
Expand All @@ -57,38 +70,47 @@ public 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);
}
}

0 comments on commit b708dfb

Please sign in to comment.