From 70cb96c1d832eccd0d7e8ab5768cf63bda6879c1 Mon Sep 17 00:00:00 2001 From: Martin Lukas Date: Sun, 15 Oct 2023 02:14:07 +0100 Subject: [PATCH 1/2] Ignore @Value on record property See gh-31433 --- .../annotation/AutowiredAnnotationBeanPostProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index a26094cd25d..dc822d85d8b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -581,7 +581,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA } return; } - if (method.getParameterCount() == 0) { + if (!method.getDeclaringClass().isRecord() && method.getParameterCount() == 0) { if (logger.isInfoEnabled()) { logger.info("Autowired annotation should only be used on methods with parameters: " + method); From f3dce4bb9ab84beaad5345a3690dbdaffc8009f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Mon, 23 Oct 2023 11:20:49 +0200 Subject: [PATCH 2/2] Polish "Ignore @Value on record property" See gh-31433 --- .../annotation/AutowiredAnnotationBeanPostProcessor.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index dc822d85d8b..17e55631597 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -581,7 +581,11 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA } return; } - if (!method.getDeclaringClass().isRecord() && method.getParameterCount() == 0) { + if (method.getParameterCount() == 0) { + if (method.getDeclaringClass().isRecord()) { + // Annotations on the compact constructor arguments made available on accessors, ignoring. + return; + } if (logger.isInfoEnabled()) { logger.info("Autowired annotation should only be used on methods with parameters: " + method);