Bean验证 - 不使用参数方法

时间:2014-04-02 09:56:06

标签: ejb-3.0 bean-validation

我有以下界面

@Local
public interface MyBeanLocal {
  @ValidUser
  int create(User user);
  String getCurrentUser();
}

和实施:

@Stateless
@MethodValidated
public class MyBean implements MyBeanLocal {

   public int create(User user) {
      String currentUser = getCurrentUser();
      user.setCreatedBy(currentUser);  
   }

   public String getCurrentUser() {
      return "test";  
   }

}

当我调用create时,我收到以下错误:

java.lang.IllegalArgumentException: HV000116: The method parameter array cannot not be null.
        at org.hibernate.validator.internal.util.Contracts.assertNotNull(Contracts.java:51)
        at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:196)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)

是否可以在方法getCurrentUser上禁用验证?

0 个答案:

没有答案