diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java index a8ab96df7efa0bafec5e3a3d864ceeba88d322fe..8239d5453a77f277b01b2c00f0a33f312287989c 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java @@ -57,6 +57,9 @@ import org.springframework.util.CollectionUtils; * {@link #setValidationMessageSource} won't work in that scenario. Please stick with * Hibernate Validator 4.3 for the time being, or upgrade to Spring Framework 4.0. * + *
This class is also being used by Spring's MVC configuration namespace, in case of the + * {@code javax.validation} API being present but no explicit Validator having been configured. + * * @author Juergen Hoeller * @since 3.0 * @see javax.validation.ValidatorFactory @@ -143,7 +146,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter /** * Specify resource locations to load XML constraint mapping files from, if any. */ - public void setMappingLocations(Resource[] mappingLocations) { + public void setMappingLocations(Resource... mappingLocations) { this.mappingLocations = mappingLocations; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java index 9af990958637c028d23582208905fd322a053d9a..464c410e25895fdde36cf71dccb7bfde98ef4228 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -19,6 +19,8 @@ package org.springframework.web.servlet.config; import java.util.List; import java.util.Properties; +import org.w3c.dom.Element; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.RuntimeBeanReference; @@ -67,7 +69,6 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.mvc.method.annotation.ServletWebArgumentResolverAdapter; import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; -import org.w3c.dom.Element; /** * A {@link BeanDefinitionParser} that provides the configuration for the @@ -125,7 +126,7 @@ import org.w3c.dom.Element; */ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { - private static final boolean jsr303Present = ClassUtils.isPresent( + private static final boolean javaxValidationPresent = ClassUtils.isPresent( "javax.validation.Validator", AnnotationDrivenBeanDefinitionParser.class.getClassLoader()); private static final boolean jaxb2Present = @@ -142,6 +143,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { private static boolean romePresent = ClassUtils.isPresent("com.sun.syndication.feed.WireFeed", AnnotationDrivenBeanDefinitionParser.class.getClassLoader()); + public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); @@ -274,8 +276,9 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { if (element.hasAttribute("validator")) { return new RuntimeBeanReference(element.getAttribute("validator")); } - else if (jsr303Present) { - RootBeanDefinition validatorDef = new RootBeanDefinition(LocalValidatorFactoryBean.class); + else if (javaxValidationPresent) { + RootBeanDefinition validatorDef = new RootBeanDefinition( + "org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"); validatorDef.setSource(source); validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); String validatorName = parserContext.getReaderContext().registerWithGeneratedName(validatorDef); @@ -324,7 +327,8 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { private RuntimeBeanReference getMessageCodesResolver(Element element, Object source, ParserContext parserContext) { if (element.hasAttribute("message-codes-resolver")) { return new RuntimeBeanReference(element.getAttribute("message-codes-resolver")); - } else { + } + else { return null; } } @@ -400,7 +404,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { ManagedList super Object> messageConverters = new ManagedList