Skip to content

Commit 380bfa3

Browse files
ngocnhan-tran1996wilkinsona
authored andcommitted
Enforce static @ConfigurationPropertyBinding @bean methods
See gh-45640 Signed-off-by: Tran Ngoc Nhan <[email protected]>
1 parent 9a2d8c5 commit 380bfa3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
* @author Scott Frederick
6060
* @author Ivan Malutin
6161
* @author Phillip Webb
62+
* @author Ngoc Nhan
6263
*/
6364
final class ArchitectureRules {
6465

@@ -88,6 +89,7 @@ static List<ArchRule> standard() {
8889
rules.add(noClassesShouldCallStringToLowerCaseWithoutLocale());
8990
rules.add(conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType());
9091
rules.add(enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType());
92+
rules.add(allConfigurationPropertiesBindingBeanMethodsShouldBeStatic());
9193
return List.copyOf(rules);
9294
}
9395

@@ -230,6 +232,14 @@ private static void notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType(Jav
230232
}
231233
}
232234

235+
private static ArchRule allConfigurationPropertiesBindingBeanMethodsShouldBeStatic() {
236+
return methodsThatAreAnnotatedWith("org.springframework.context.annotation.Bean").and()
237+
.areAnnotatedWith("org.springframework.boot.context.properties.ConfigurationPropertiesBinding")
238+
.should()
239+
.beStatic()
240+
.allowEmptyShould(true);
241+
}
242+
233243
private static boolean containsOnlySingleType(JavaType[] types, JavaType type) {
234244
return types.length == 1 && type.equals(types[0]);
235245
}

0 commit comments

Comments
 (0)