Skip to content

Migration to Spring Batch 5.2 : StepBuilderFactory/JobBuilderFactory partially migrated when used as constructor arguments #789

@geoffroyc

Description

@geoffroyc

The private declarations of type StepBuilderFactory and JobBuilderFactory are removed, but the StepBuilderFactory type argument is not removed from the constructor. The imports are also not removed. The constructor contents are also not adapted.

What version of OpenRewrite are you using?

I am using

  • rewrite-maven-plugin:6.18.0
  • org.openrewrite.recipe:rewrite-spring v6.15.0
  • org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_5 -> org.openrewrite.java.spring.batch.SpringBatch4To5Migration -> org.openrewrite.java.spring.batch.MigrateStepBuilderFactory

How are you running OpenRewrite?

using the Maven plugin

What is the smallest, simplest way to reproduce the problem?

Before :

import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyJobConfiguration {
    private final StepBuilderFactory steps;
    private final JobBuilderFactory jobBuilderFactory;

    @Autowired
    public MyJobConfiguration(StepBuilderFactory steps, JobBuilderFactory jobBuilderFactory) {
        this.steps = steps;
        this.jobBuilderFactory = jobBuilderFactory;
    }

}

What did you expect to see?

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyJobConfiguration {

    @Autowired
    public MyJobConfiguration() {
    }
}

Or, perhups, in some cases :

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyJobConfiguration {

    private final JobRepository jobRepository;
    private final PlatformTransactionManager transactionManager;

    @Autowired
    public MyJobConfiguration(JobRepository jobRepository,
                                                PlatformTransactionManager transactionManager) {
        this.jobRepository = jobRepository;
        this.transactionManager = transactionManager;
    }
}

What did you see instead?

import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.step.builder.StepBuilder;

import org.springframework.context.annotation.Configuration;

@Configuration
public class MyJobConfiguration {

    public MyJobConfiguration(StepBuilderFactory steps) {
        this.steps = steps;
        this.jobBuilderFactory = jobBuilderFactory;
    }
}

Are you interested in [contributing a fix to OpenRewrite]

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions