title: Optional @Pathvariable in REST controller spring 4
body: <p>I'm writing a Rest Service (HTTP Get endpoint), where in the below uri does the following</p>
  
  <pre><code>http://localhost:8080/customers/{customer_id}
  </code></pre>
  
  <ol>
  <li>fetch the details for the customer_id passed in the uri</li>
  <li>if the customer_id is not passed (<a href="http://localhost:8080/customers" rel="nofollow noreferrer">http://localhost:8080/customers</a>), fetch all the customers details. </li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET, value = "customers/{customer_id}")
  public List&lt;Customer&gt; getCustomers(
  @PathVariable(name = "customer_id", required = false) final String customerId) {
  LOGGER.debug("customer_id {} received for getCustomers request", customerId);
  
  }
  </code></pre>
  
  <p>However, with the above code, for the second scenario control is flowing to  getCustomers().</p>
  
  <p>Note: I'm using Java8 and spring-web 4.3.10 version</p>
  
  <p>Highly appreciate any help on this.</p>