49
49
import org .springframework .context .ApplicationContext ;
50
50
import org .springframework .context .ApplicationContextAware ;
51
51
import org .springframework .context .MessageSource ;
52
- import org .springframework .core .DefaultParameterNameDiscoverer ;
52
+ import org .springframework .core .KotlinDetector ;
53
+ import org .springframework .core .KotlinReflectionParameterNameDiscoverer ;
53
54
import org .springframework .core .ParameterNameDiscoverer ;
54
55
import org .springframework .core .io .Resource ;
55
56
import org .springframework .lang .Nullable ;
@@ -100,7 +101,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
100
101
private ConstraintValidatorFactory constraintValidatorFactory ;
101
102
102
103
@ Nullable
103
- private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer () ;
104
+ private ParameterNameDiscoverer parameterNameDiscoverer ;
104
105
105
106
@ Nullable
106
107
private Resource [] mappingLocations ;
@@ -117,6 +118,13 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
117
118
private ValidatorFactory validatorFactory ;
118
119
119
120
121
+ public LocalValidatorFactoryBean () {
122
+ if (KotlinDetector .isKotlinReflectPresent ()) {
123
+ this .parameterNameDiscoverer = new KotlinReflectionParameterNameDiscoverer ();
124
+ }
125
+ }
126
+
127
+
120
128
/**
121
129
* Specify the desired provider class, if any.
122
130
* <p>If not specified, JSR-303's default search mechanism will be used.
@@ -188,7 +196,10 @@ public void setConstraintValidatorFactory(ConstraintValidatorFactory constraintV
188
196
/**
189
197
* Set the ParameterNameDiscoverer to use for resolving method and constructor
190
198
* parameter names if needed for message interpolation.
191
- * <p>Default is a {@link org.springframework.core.DefaultParameterNameDiscoverer}.
199
+ * <p>Default is Hibernate Validator's own internal use of standard Java reflection,
200
+ * with an additional {@link KotlinReflectionParameterNameDiscoverer} if Kotlin
201
+ * is present. This may be overridden with a custom subclass or a Spring-controlled
202
+ * {@link org.springframework.core.DefaultParameterNameDiscoverer} if necessary,
192
203
*/
193
204
public void setParameterNameDiscoverer (ParameterNameDiscoverer parameterNameDiscoverer ) {
194
205
this .parameterNameDiscoverer = parameterNameDiscoverer ;
0 commit comments