spring-projects-experimental / spring-boot-migrator

Spring Boot Migrator (SBM) is a tool for automated code migrations to upgrade or migrate to Spring Boot
Apache License 2.0
444 stars 88 forks source link

Migrated Spring application properties must be reflected everywhere they can be used #471

Open fabapp2 opened 2 years ago

fabapp2 commented 2 years ago

What needs to be done

When Spring application properties are changed or removed usages outside of .properties/.yaml files need to be adjusted. For example, here the properties must be detected and changed.

@SpringBootTest(properties={...})

Other places are @PropertySource and there are other potential references (@Value,...) that must be changed.

Thoughts

It might be a good idea to enhance the SpringBootApplicationProperties resources for all properties related components so that it represents a composition of all configuration-related resources (@Value, @PropertySource, Profile information, usages of a property with System. and Environment and other locations`). We then provide an API to e.g. change a property and adjust all locations.

Given

some.prop=value
@Component
@ConfigurationProperties(prefix = "some")
@Getter
@Setter
public class MyApplicationProperties {
    private String prop;
}

Apply

SpringBootConfigurationInformation configInfo = context.search(new SpringBootConfigurationInformationFinder());
configInfo.renameProperty("some.prop", "another.property")

Result

another.property=value
@Component
@ConfigurationProperties(prefix="another")
@Getter
@Setter
public class MyApplicationProperties {
    private String property;
}

What needs to be done

The enhanced SpringBootApplicationProperties class should handle all "externalized configuration"

tkvangorder commented 1 year ago

@fabapp2 I have created a new recipe, ChangeSpringPropertyKey to encapsulate the renaming of a spring boot application property. This recipe will rename the key in .yml, .yaml, and .properties files.

We can expand this recipe to add Java visitors that will make the renames within Java source code.