title: Validating JMS payload in Spring
body: <p>I have a simple service sending emails. It can be invoked using REST and JMS APIs. I want the requests to be validated before processing.</p>
  
  <p>When I invoke it using REST I can see that <code>org.springframework.validation.DataBinder</code> invokes <code>void validate(Object target, Errors errors, Object... validationHints)</code> and then validator from Hibernate is invoked. This works as expected.</p>
  
  <p>The problem is I can't achieve the same effect with JMS Listener. The listener is implemented as follows:</p>
  
  <pre class="lang-js prettyprint-override"><code>import lombok.AllArgsConstructor;
  import lombok.extern.slf4j.Slf4j;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  import org.springframework.jms.annotation.JmsListener;
  import org.springframework.stereotype.Component;
  import our.domain.mailing.Mailing;
  import our.domain.mailing.jms.api.SendEmailFromTemplateRequest;
  import our.domain.mailing.jms.api.SendSimpleEmailRequest;
  import javax.validation.Valid;
  
  @ConditionalOnProperty("jms.configuration.destination")
  @Component
  @AllArgsConstructor(onConstructor = @__(@Autowired))
  @Slf4j
  public class SendMailMessageListener {
      Mailing mailing;
  
      @JmsListener(destination = "${jms.configuration.destination}")
      public void sendEmailUsingTemplate(@Valid SendEmailFromTemplateRequest request) {
          log.debug("Received jms message: {}", request);
          mailing.sendEmailTemplate(
                  request.getEmailDetails().getRecipients(),
                  request.getEmailDetails().getAccountType(),
                  request.getTemplateDetails().getTemplateCode(),
                  request.getTemplateDetails().getLanguage(),
                  request.getTemplateDetails().getParameters());
      }
  
      @JmsListener(destination = "${jms.configuration.destination}")
      public void sendEmail(@Valid SendSimpleEmailRequest request) {
          log.debug("Received jms message: {}", request);
          mailing.sendEmail(
                  request.getRecipients(),
                  request.getSubject(),
                  request.getMessage());
      }
  }
  </code></pre>
  
  <p>The methods receive payloads but they are not validated. It's Spring Boot application and I have <code>@EnableJms</code> added. Can you guide what part of Spring source code is responsible for discovering <code>@Validate</code> and handling it? If you have any hints on how to make it running I would appreciate it a lot.</p>