title: How to globally configure `@DateTimeFormat` pattern in Spring Boot?
body: <p>Im my Spring Boot application, I have some controllers that accept a date as query parameter:</p>
  
  <pre><code>@RestController
  public class MyController {
  
    @GetMapping
    public ResponseEntity&lt;?&gt; getDataByDate(
        @RequestParam(value = "date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
        final LocalDate date) {
      return ResponseEntity.ok();
    }
  }
  </code></pre>
  
  <p>This works well, and I can even mark the parameter as optional using <code>@RequestParam(value = "date", required = false)</code> and then use an <code>Optional&lt;LocalDate&gt;</code>. Spring will handle all this and pass an empty Optional when the parameter is missing.</p>
  
  <p>Since I have several controllers using dates as query parameters, I want to configure this behavior for all <code>LocalDate</code> query parameters. I have tried the <code>spring.mvc.date-pattern</code> property, but it only seems to work for <code>java.util.Date</code>.</p>
  
  <p>So after searching the web, the best I came up with is a <code>ControllerAdvice</code> I adopted from this <a href="https://stackoverflow.com/a/43726183/5391954">answer</a>. The problem with this solution is, that is can not handle <code>Optional&lt;LocalDate&gt;</code> anymore. It feels like this is the wrong way to configure the behavior in Spring Boot.</p>
  
  <p>So my question is: How do I globally configure the pattern for <code>LocalDate</code> used as query parameters in an idiomatic way in Spring Boot?</p>