title: Spring @Validated in service layer
body: <p>Hej,</p>
  
  <p>I want to use the <code>@Validated(group=Foo.class)</code> annotation to validate an argument before executing a method like following:</p>
  
  <pre><code>public void doFoo(Foo @Validated(groups=Foo.class) foo){}
  </code></pre>
  
  <p>When i put this method in the Controller of my Spring application, the <code>@Validated</code> is executed and throws an error when the Foo object is not valid. However if I put the same thing in a method in the Service layer of my application, the validation is not executed and the method just runs even when the Foo object isn't valid.</p>
  
  <p>Can't you use the <code>@Validated</code> annotation in the service layer ? Or do I have to do configure something extra to make it work ?</p>
  
  <p>Update:</p>
  
  <p>I have added the following two beans to my service.xml:</p>
  
  <pre><code>&lt;bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/&gt;
  &lt;bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor"/&gt;
  </code></pre>
  
  <p>and replaced the <code>@Validate</code> with <code>@Null</code> like so:</p>
  
  <pre><code>public void doFoo(Foo @Null(groups=Foo.class) foo){}
  </code></pre>
  
  <p>I know it is a pretty silly annotation to do but I wanted to check that if I call the method now and passing null it would throw an violation exception which it does. So why does it execute the <code>@Null</code> annotation and not the <code>@Validate</code> annotation ? I know one is from <code>javax.validation</code> and the other is from Spring but I do not think that has anything to do with it ?  </p>