Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -57,9 +57,9 @@ public class AutoProxyRegistrar implements ImportBeanDefinitionRegistrar {
|
||||
@Override
|
||||
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
|
||||
boolean candidateFound = false;
|
||||
Set<String> annoTypes = importingClassMetadata.getAnnotationTypes();
|
||||
for (String annoType : annoTypes) {
|
||||
AnnotationAttributes candidate = AnnotationConfigUtils.attributesFor(importingClassMetadata, annoType);
|
||||
Set<String> annTypes = importingClassMetadata.getAnnotationTypes();
|
||||
for (String annType : annTypes) {
|
||||
AnnotationAttributes candidate = AnnotationConfigUtils.attributesFor(importingClassMetadata, annType);
|
||||
if (candidate == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -135,7 +135,7 @@ public class DefaultMessageSourceResolvable implements MessageSourceResolvable,
|
||||
* including codes, arguments, and default message.
|
||||
*/
|
||||
protected final String resolvableToString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
StringBuilder result = new StringBuilder(64);
|
||||
result.append("codes [").append(StringUtils.arrayToDelimitedString(this.codes, ","));
|
||||
result.append("]; arguments [").append(StringUtils.arrayToDelimitedString(this.arguments, ","));
|
||||
result.append("]; default message [").append(this.defaultMessage).append(']');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -358,9 +358,9 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||
|
||||
/**
|
||||
* Register a bean from the given bean class, optionally customizing its
|
||||
* bean definition metadata (typically declared as a lambda expression
|
||||
* or method reference).
|
||||
* @param beanClass the class of the bean
|
||||
* bean definition metadata (typically declared as a lambda expression).
|
||||
* @param beanClass the class of the bean (resolving a public constructor
|
||||
* to be autowired, possibly simply the default constructor)
|
||||
* @param customizers one or more callbacks for customizing the factory's
|
||||
* {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
|
||||
* @since 5.0
|
||||
@@ -371,18 +371,19 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a bean from the given bean class, using the given supplier for
|
||||
* obtaining a new instance (typically declared as a lambda expression or
|
||||
* method reference), optionally customizing its bean definition metadata
|
||||
* (again typically declared as a lambda expression or method reference).
|
||||
* Register a bean from the given bean class, optionally customizing its
|
||||
* bean definition metadata (typically declared as a lambda expression).
|
||||
* @param beanName the name of the bean (may be {@code null})
|
||||
* @param beanClass the class of the bean
|
||||
* @param beanClass the class of the bean (resolving a public constructor
|
||||
* to be autowired, possibly simply the default constructor)
|
||||
* @param customizers one or more callbacks for customizing the factory's
|
||||
* {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
|
||||
* @since 5.0
|
||||
* @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...)
|
||||
*/
|
||||
public final <T> void registerBean(@Nullable String beanName, Class<T> beanClass, BeanDefinitionCustomizer... customizers) {
|
||||
public final <T> void registerBean(
|
||||
@Nullable String beanName, Class<T> beanClass, BeanDefinitionCustomizer... customizers) {
|
||||
|
||||
registerBean(beanName, beanClass, null, customizers);
|
||||
}
|
||||
|
||||
@@ -390,7 +391,7 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||
* Register a bean from the given bean class, using the given supplier for
|
||||
* obtaining a new instance (typically declared as a lambda expression or
|
||||
* method reference), optionally customizing its bean definition metadata
|
||||
* (again typically declared as a lambda expression or method reference).
|
||||
* (again typically declared as a lambda expression).
|
||||
* @param beanClass the class of the bean
|
||||
* @param supplier a callback for creating an instance of the bean
|
||||
* @param customizers one or more callbacks for customizing the factory's
|
||||
@@ -398,7 +399,9 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||
* @since 5.0
|
||||
* @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...)
|
||||
*/
|
||||
public final <T> void registerBean(Class<T> beanClass, Supplier<T> supplier, BeanDefinitionCustomizer... customizers) {
|
||||
public final <T> void registerBean(
|
||||
Class<T> beanClass, Supplier<T> supplier, BeanDefinitionCustomizer... customizers) {
|
||||
|
||||
registerBean(null, beanClass, supplier, customizers);
|
||||
}
|
||||
|
||||
@@ -406,18 +409,19 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||
* Register a bean from the given bean class, using the given supplier for
|
||||
* obtaining a new instance (typically declared as a lambda expression or
|
||||
* method reference), optionally customizing its bean definition metadata
|
||||
* (again typically declared as a lambda expression or method reference).
|
||||
* (again typically declared as a lambda expression).
|
||||
* <p>This method can be overridden to adapt the registration mechanism for
|
||||
* all {@code registerBean} methods (since they all delegate to this one).
|
||||
* @param beanName the name of the bean (may be {@code null})
|
||||
* @param beanClass the class of the bean
|
||||
* @param supplier a callback for creating an instance of the bean
|
||||
* @param supplier a callback for creating an instance of the bean (in case
|
||||
* of {@code null}, resolving a public constructor to be autowired instead)
|
||||
* @param customizers one or more callbacks for customizing the factory's
|
||||
* {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
|
||||
* @since 5.0
|
||||
*/
|
||||
public <T> void registerBean(@Nullable String beanName, Class<T> beanClass, @Nullable Supplier<T> supplier,
|
||||
BeanDefinitionCustomizer... customizers) {
|
||||
public <T> void registerBean(@Nullable String beanName, Class<T> beanClass,
|
||||
@Nullable Supplier<T> supplier, BeanDefinitionCustomizer... customizers) {
|
||||
|
||||
BeanDefinitionBuilder builder = (supplier != null ?
|
||||
BeanDefinitionBuilder.genericBeanDefinition(beanClass, supplier) :
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,13 +50,17 @@ import org.springframework.validation.SmartValidator;
|
||||
* while also exposing the original JSR-303 Validator interface itself.
|
||||
*
|
||||
* <p>Can be used as a programmatic wrapper. Also serves as base class for
|
||||
* {@link CustomValidatorBean} and {@link LocalValidatorFactoryBean}.
|
||||
* {@link CustomValidatorBean} and {@link LocalValidatorFactoryBean},
|
||||
* and as the primary implementation of the {@link SmartValidator} interface.
|
||||
*
|
||||
* <p>As of Spring Framework 5.0, this adapter is fully compatible with
|
||||
* Bean Validation 1.1 as well as 2.0.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
* @see SmartValidator
|
||||
* @see CustomValidatorBean
|
||||
* @see LocalValidatorFactoryBean
|
||||
*/
|
||||
public class SpringValidatorAdapter implements SmartValidator, javax.validation.Validator {
|
||||
|
||||
@@ -141,7 +145,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
|
||||
// as necessary for Hibernate Validator compatibility (non-indexed set path in field)
|
||||
BindingResult bindingResult = (BindingResult) errors;
|
||||
String nestedField = bindingResult.getNestedPath() + field;
|
||||
if ("".equals(nestedField)) {
|
||||
if (nestedField.isEmpty()) {
|
||||
String[] errorCodes = bindingResult.resolveMessageCodes(errorCode);
|
||||
ObjectError error = new ObjectError(
|
||||
errors.getObjectName(), errorCodes, errorArgs, violation.getMessage());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -284,6 +284,8 @@ public class ValidatorFactoryTests {
|
||||
validator.validate(listContainer, errors);
|
||||
|
||||
FieldError fieldError = errors.getFieldError("list[1]");
|
||||
assertNotNull(fieldError);
|
||||
assertEquals("X", fieldError.getRejectedValue());
|
||||
assertEquals("X", errors.getFieldValue("list[1]"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user