Spring的@Validated忽略了没有组的自定义约束

时间:2016-05-24 00:00:04

标签: spring spring-mvc bean-validation

我有控制器方法:

&http.Transport{idleMu:sync.Mutex{state:0, sema:0x0}, 
                         idleConn:map[http.connectMethodKey][]*http.persistConn(nil), 
                         idleConnCh:map[http.connectMethodKey]chan *http.persistConn(nil), 
                         reqMu:sync.Mutex{state:0, sema:0x0}, 
                         reqCanceler:map[*http.Request]func()(nil), 
                         altMu:sync.RWMutex{w:sync.Mutex{state:0, sema:0x0}, 
                         writerSem:0x0, 
                         readerSem:0x0, 
                         readerCount:0, 
                         readerWait:0}, 
                         altProto:map[string]http.RoundTripper(nil), 
                         Proxy:(func(*http.Request) (*url.URL, error))(nil), 
                         Dial:(func(string, string) (net.Conn, error))(nil), 
                         TLSClientConfig:(*tls.Config)(nil), 
                         TLSHandshakeTimeout:0, 
                         DisableKeepAlives:false, 
                         DisableCompression:false, 
                         MaxIdleConnsPerHost:200, 
                         ResponseHeaderTimeout:0}

和BookingForm包含一个字段和我的自定义验证器:

void save(@Validated(BookingForm.ValidationSave.class) @RequestBody BookingForm form, Errors result) {...}

Future.java

public class BookingForm {

   public interface ValidationSave {}
   public interface ValidationEstimate {}    
   ....
   @Future
   private LocalDateTime when;
   ....
}

我预计验证器会对我的'when'字段有效,但事实并非如此。 当我从@Validated中删除该组时,它可以工作。有任何想法吗? 适用于@NotNull和其他javax验证器。

更新 FutureValidator.java

@Target({ ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = FutureValidator.class)
@Documented
public @interface Future {

   String message() default "{javax.validation.constraints.Future.message}";

   Class<?>[] groups() default {};

   Class<? extends Payload>[] payload() default {};

}

0 个答案:

没有答案