title: Validation not working in Java Spring Application
body: <p>I added the correct validation annotations to my DTO and API class, but when I input bad data thru postman, it doesn't error.</p>
  <p>API Class</p>
  <pre><code>@RestController
  @RequestMapping(&quot;/laptops&quot;)
  @Validated
  public class LaptopApi
  {
      @Autowired
      private LaptopService laptopService;
  
      @Autowired
      private Environment environment;
  
      @GetMapping(&quot;/{id}&quot;)
      public ResponseEntity&lt;LaptopDTO&gt; getLaptop(@PathVariable Integer id)
      {
          LaptopDTO laptop = laptopService.getLaptop(id);
          return new ResponseEntity&lt;&gt;(laptop, HttpStatus.OK);
      }
  
      @GetMapping(&quot;/&quot;)
      public ResponseEntity&lt;List&lt;LaptopDTO&gt;&gt; getLaptops()
      {
          List&lt;LaptopDTO&gt; laptops = laptopService.getLaptops();
          return new ResponseEntity&lt;&gt;(laptops, HttpStatus.OK);
      }
  
      @PostMapping(&quot;/&quot;)
      public ResponseEntity&lt;LaptopDTO&gt; addLaptop(@RequestBody @Valid LaptopDTO laptopDTO)
      {
          Integer laptopId = laptopService.addLaptop(laptopDTO);
          return new ResponseEntity&lt;&gt;(laptopDTO, HttpStatus.OK);
      }
  
      @PutMapping(&quot;/&quot;)
      public ResponseEntity&lt;LaptopDTO&gt; updateSpecs(@RequestBody @Valid LaptopDTO laptopDTO)
      {
          laptopService.updateSpecs(laptopDTO);
          return new ResponseEntity&lt;&gt;(laptopDTO, HttpStatus.OK);
      }
  
      @DeleteMapping(&quot;{id}&quot;)
      public ResponseEntity&lt;String&gt; deleteLaptop(@PathVariable Integer id)
      {
          laptopService.deleteLaptop(id);
          return new ResponseEntity&lt;&gt;(environment.getProperty(&quot;API.LAPTOP_DELETE_SUCCESS&quot;)+&quot; &quot;+id,
                  HttpStatus.OK);
      }
  </code></pre>
  <p>DTO Class (I ran the regex checks on a unit test, which works correctly)</p>
  <pre><code>public class LaptopDTO
  {
      private Integer id;
  
      @NotNull
      private String name;
  
      @NotNull
      @Pattern(regexp = &quot;(Intel core i[3579] [0-9]{4,}[A-Za-z]*)&quot; +
                          &quot;|(AMD Ryzen [3579] [0-9]{4,}[A-Za-z]*)&quot;,
              message = &quot;microcenter.cpu.invalid&quot;)
      private String cpu;
  
      @NotNull
      @Min(value = 4)
      private Integer ram;
  
      @NotNull
      private Integer nvme;
  
      @NotNull
      private Integer ssd;
  
      @NotNull
      private Integer hdd;
  
      @NotNull
      @Pattern(regexp = &quot;(Intel U?HD [56][23]0)|&quot; +
                          &quot;([Nn]vidia Geforce [GR]TX [123][06][5678]0)(| super| Ti)&quot;,
              message = &quot;microcenter.gpu.invalid&quot;)
      private String gpu;
    
     ... //constructors and methods
    }
  </code></pre>
  <p>JSON Request Body:</p>
  <pre><code>{
      &quot;name&quot;: &quot;asegjbofld;bsgj&quot;,
      &quot;cpu&quot;: &quot;radhtrhsth&quot;,
      &quot;ram&quot;: 2,
      &quot;nvme&quot;: 512,
      &quot;ssd&quot;: 1000,
      &quot;hdd&quot;: 2000,
      &quot;gpu&quot;: &quot;newga&quot;
  }
  </code></pre>
  <p>Based on the invalid cpu and gpu input from the json request body, it is supposed to error, because of the gpu and cpu, but the request gets processed?  Any ideas on how to fix? Thanks.</p>
  <p>POM.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.3.3.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.microcenter&lt;/groupId&gt;
      &lt;artifactId&gt;MicroCenter&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;MicroCenter&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                      &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.validation&lt;/groupId&gt;
              &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
              &lt;version&gt;1.1.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>