Merge branch '3.4.x'

Closes gh-45653
This commit is contained in:
Andy Wilkinson
2025-05-23 14:31:28 +01:00
5 changed files with 22 additions and 12 deletions

View File

@@ -64,6 +64,7 @@ import org.springframework.util.ResourceUtils;
* @author Scott Frederick
* @author Ivan Malutin
* @author Phillip Webb
* @author Ngoc Nhan
*/
final class ArchitectureRules {
@@ -96,6 +97,7 @@ final class ArchitectureRules {
rules.add(classLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute());
rules.add(methodLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute());
rules.add(conditionsShouldNotBePublic());
rules.add(allConfigurationPropertiesBindingBeanMethodsShouldBeStatic());
return List.copyOf(rules);
}
@@ -309,6 +311,14 @@ final class ArchitectureRules {
.allowEmptyShould(true);
}
private static ArchRule allConfigurationPropertiesBindingBeanMethodsShouldBeStatic() {
return methodsThatAreAnnotatedWith("org.springframework.context.annotation.Bean").and()
.areAnnotatedWith("org.springframework.boot.context.properties.ConfigurationPropertiesBinding")
.should()
.beStatic()
.allowEmptyShould(true);
}
private static boolean containsOnlySingleType(JavaType[] types, JavaType type) {
return types.length == 1 && type.equals(types[0]);
}

View File

@@ -113,7 +113,7 @@ public class FlywayAutoConfiguration {
@Bean
@ConfigurationPropertiesBinding
public StringOrNumberToMigrationVersionConverter stringOrNumberMigrationVersionConverter() {
public static StringOrNumberToMigrationVersionConverter stringOrNumberMigrationVersionConverter() {
return new StringOrNumberToMigrationVersionConverter();
}

View File

@@ -264,7 +264,7 @@ class SecurityAutoConfigurationTests {
@Bean
@ConfigurationPropertiesBinding
Converter<String, TargetType> targetTypeConverter() {
static Converter<String, TargetType> targetTypeConverter() {
return new Converter<>() {
@Override

View File

@@ -1593,7 +1593,7 @@ class ConfigurationPropertiesTests {
@Bean
@ConfigurationPropertiesBinding
Converter<String, Person> personConverter() {
static Converter<String, Person> personConverter() {
return new PersonConverter();
}
@@ -1604,7 +1604,7 @@ class ConfigurationPropertiesTests {
@Bean
@ConfigurationPropertiesBinding
Converter<String, Alien> alienConverter() {
static Converter<String, Alien> alienConverter() {
return new AlienConverter();
}
@@ -1625,7 +1625,7 @@ class ConfigurationPropertiesTests {
@Bean
@ConfigurationPropertiesBinding
GenericConverter genericPersonConverter() {
static GenericConverter genericPersonConverter() {
return new GenericPersonConverter();
}
@@ -1636,7 +1636,7 @@ class ConfigurationPropertiesTests {
@Bean
@ConfigurationPropertiesBinding
Formatter<Person> personFormatter() {
static Formatter<Person> personFormatter() {
return new PersonFormatter();
}
@@ -3064,7 +3064,7 @@ class ConfigurationPropertiesTests {
@Bean
@ConfigurationPropertiesBinding
WithObjectToObjectMethodConverter withObjectToObjectMethodConverter() {
static WithObjectToObjectMethodConverter withObjectToObjectMethodConverter() {
return new WithObjectToObjectMethodConverter();
}

View File

@@ -129,13 +129,13 @@ class ConversionServiceDeducerTests {
@Bean
@ConfigurationPropertiesBinding
TestConverter testConverter() {
static TestConverter testConverter() {
return new TestConverter();
}
@Bean
@ConfigurationPropertiesBinding
StringConverter stringConverter() {
static StringConverter stringConverter() {
return new StringConverter();
}
@@ -146,13 +146,13 @@ class ConversionServiceDeducerTests {
@Bean
@ConfigurationPropertiesBinding
Converter<InputStream, OutputStream> testConverter() {
static Converter<InputStream, OutputStream> testConverter() {
return (source) -> new TestConverter().convert(source);
}
@Bean
@ConfigurationPropertiesBinding
Converter<String, InputStream> stringConverter() {
static Converter<String, InputStream> stringConverter() {
return (source) -> new StringConverter().convert(source);
}
@@ -163,7 +163,7 @@ class ConversionServiceDeducerTests {
@Bean
@ConfigurationPropertiesBinding
Printer<InputStream> inputStreamPrinter() {
static Printer<InputStream> inputStreamPrinter() {
return (source, locale) -> ThrowingSupplier
.of(() -> StreamUtils.copyToString(source, StandardCharsets.UTF_8))
.get();