001/* 002 * Copyright 2002-2014 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.validation.annotation; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023import java.lang.annotation.Target; 024 025/** 026 * Variant of JSR-303's {@link javax.validation.Valid}, supporting the 027 * specification of validation groups. Designed for convenient use with 028 * Spring's JSR-303 support but not JSR-303 specific. 029 * 030 * <p>Can be used e.g. with Spring MVC handler methods arguments. 031 * Supported through {@link org.springframework.validation.SmartValidator}'s 032 * validation hint concept, with validation group classes acting as hint objects. 033 * 034 * <p>Can also be used with method level validation, indicating that a specific 035 * class is supposed to be validated at the method level (acting as a pointcut 036 * for the corresponding validation interceptor), but also optionally specifying 037 * the validation groups for method-level validation in the annotated class. 038 * Applying this annotation at the method level allows for overriding the 039 * validation groups for a specific method but does not serve as a pointcut; 040 * a class-level annotation is nevertheless necessary to trigger method validation 041 * for a specific bean to begin with. Can also be used as a meta-annotation on a 042 * custom stereotype annotation or a custom group-specific validated annotation. 043 * 044 * @author Juergen Hoeller 045 * @since 3.1 046 * @see javax.validation.Validator#validate(Object, Class[]) 047 * @see org.springframework.validation.SmartValidator#validate(Object, org.springframework.validation.Errors, Object...) 048 * @see org.springframework.validation.beanvalidation.SpringValidatorAdapter 049 * @see org.springframework.validation.beanvalidation.MethodValidationPostProcessor 050 */ 051@Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER}) 052@Retention(RetentionPolicy.RUNTIME) 053@Documented 054public @interface Validated { 055 056 /** 057 * Specify one or more validation groups to apply to the validation step 058 * kicked off by this annotation. 059 * <p>JSR-303 defines validation groups as custom annotations which an application declares 060 * for the sole purpose of using them as type-safe group arguments, as implemented in 061 * {@link org.springframework.validation.beanvalidation.SpringValidatorAdapter}. 062 * <p>Other {@link org.springframework.validation.SmartValidator} implementations may 063 * support class arguments in other ways as well. 064 */ 065 Class<?>[] value() default {}; 066 067}