diff --git a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java index 3dc1dae043..a097c2ce2a 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java @@ -59,6 +59,7 @@ import org.springframework.util.ResourceUtils; * @author Scott Frederick * @author Ivan Malutin * @author Phillip Webb + * @author Ngoc Nhan */ final class ArchitectureRules { @@ -88,6 +89,7 @@ final class ArchitectureRules { rules.add(noClassesShouldCallStringToLowerCaseWithoutLocale()); rules.add(conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType()); rules.add(enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType()); + rules.add(allConfigurationPropertiesBindingBeanMethodsShouldBeStatic()); return List.copyOf(rules); } @@ -230,6 +232,14 @@ final class ArchitectureRules { } } + 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]); }