title: Spring MVC validation throws ConstraintViolationException
body: <p>I want to validate the bean class Articolo, which is an attribute of the model class NewEditArticle, whose instances are created in a controller and passed to a view ArticleManager.jsp.</p>
  
  <p>This view is a form to insert, update or delete articles in a SQL db. </p>
  
  <p>I tried to implement an annotation-based validation system, but for some reason it doesn't work: if, for example, I submit the form without populating one of the fields marked as NotEmpty/NotNull inside the bean class, the system throws a validation-related exception, but nothing is captured from the BindingResult. </p>
  
  <p>As far as I understand from the error message, the validation sort of works, but result.hasErrors() doesn't capture anything, therefore it doesn't return the form displaying the error messages.</p>
  
  <p>Any idea where the problem is and how to fix it?</p>
  
  <p>N.B:  I already have <code>mvc:annotation-driven</code> in my config.</p>
  
  <p>Bean class</p>
  
  <pre><code>@Entity
  @Table (name="Articolo")
  public class Articolo {
  
  @Id
  @GeneratedValue (strategy=GenerationType.IDENTITY)
  @Column (name="ID")
  @NotNull (message="error")
  private int id;
  
  @Column (name="Ristorante")
  @NotEmpty (message="error")
  private String ristorante;
  
  @Column (name="Data")
  @NotEmpty (message="error")
  private String data;
  
  @Column (name="Articolo")
  @NotEmpty (message="error")
  private String articolo;
  
  @Column (name="IDArea")
  @NotNull (message="error")
  private int IDArea;
  
  @Column (name="IDCucina")
  @NotNull (message="error")
  private int IDCucina;
  
  @Column (name="IDPrezzo")
  @NotNull (message="error")
  private int IDPrezzo;
  
  @Column (name="IDVoto")
  @NotNull (message="error")
  private int IDVoto;
  
  @Column (name="Foto")
  private String foto;
  
  
  //CONSTRUCTORS, GETTERS AND SETTERS
  </code></pre>
  
  <p>Model class</p>
  
  <pre><code>public class NewEditArticolo {
  
  //ATTRIBUTES
  private Articolo articolo;
  private List&lt;Area&gt; ListaArea;
  private List&lt;Cucina&gt; ListaCucina;
  private List&lt;Prezzo&gt; ListaPrezzo;
  private List&lt;Voto&gt; ListaVoto;
  private List&lt;String&gt; ListaImg;
  
  
  
  
  //METHODS
  
  //CONSTRUCTOR
  
  public NewEditArticolo () {
  
  }
  
  //create Article model based on ID number
  //if ID=0 (new Article), creates empty model
  public NewEditArticolo(int ID) throws SQLException {
  
      //call DAOArticolo.select only if article already exists
      if (ID != 0) {
          DAOArticolo DAOart = new DAOArticolo();
          articolo = DAOart.select(ID);
      }
  
      //return list of all objects from table Area
      DAOArea DAOa = new DAOArea();
      ListaArea = DAOa.getArea();
  
      //return list of all objects from table Cucina
      DAOCucina DAOc = new DAOCucina();
      ListaCucina = DAOc.getCucina();
  
      //return list of all objects from table Prezzo
      DAOPrezzo DAOp = new DAOPrezzo();
      ListaPrezzo = DAOp.getPrezzo();
  
      //return list of all objects from table Voto
      DAOVoto DAOv = new DAOVoto();
      ListaVoto = DAOv.getVoto();
  
      ListaImg = new ArrayList&lt;String&gt;();
  
  
      // create array containing the path of all files in folder img
      File folder = new File("C:/Users/Ale/workspace/SpringMVCBlog/WebContent/resources/img");
      File[] arrayImg = folder.listFiles();
      // get the name of each file in the array and add it to ListaImg
      for (File f : arrayImg) {
          String fileName=f.getName();
          ListaImg.add(fileName);
      }
  
  }
  
  //GETTERS AND SETTERS
  </code></pre>
  
  <p>Servlet class</p>
  
  <pre><code>    @Controller
   public class ArticleManagerController {
  
  @RequestMapping (value="/ArticleManager", method= RequestMethod.GET)
  
  //creates model and pass it to view ARTICLEMANAGER.JSP
  public ModelAndView createArticleManager(@RequestParam(value = "IDarticolo") int IDarticolo) {
  
      ModelAndView model=new ModelAndView("ArticleManager");
  
      //get article based on ID number from URL
      //if ID=0, creates empty model (new article)
  
          try {
              NewEditArticolo nea = new NewEditArticolo(IDarticolo);
              model.addObject("nea", nea);
  
          }
  
          catch (SQLException e) {
              System.out.println("failed to generate model for article with ID " + IDarticolo);
              e.printStackTrace();
          }
  
  
      return model;
  
  }
  
  // insert, edit or delete article in DB
  @RequestMapping (value="/ArticleManager", method=RequestMethod.POST)
  
  public String editArticle ( Model model,
                              @Valid @ModelAttribute (value="nea") NewEditArticolo nea, //create NewEditArticolo object, autowire attributes from ArticleManager.jsp, add to model and validate
                              BindingResult result, //collect validation errors
                              @RequestParam (value="submit") String submit){ //get input value from ArticleManager.jsp
  
      Articolo articolo1=nea.getArticolo();
  
      DAOArticolo daoArt = new DAOArticolo();
  
      //if validation fails, return form to display validation errors
      if (result.hasErrors()) {
          System.out.println("VALIDATION FAILED");
          return "ArticleManager";
      }
  
      else {
          System.out.println("VALIDATION WAS SUCCESFULL");
      }
  
  
      switch (submit) {
  
      case "SUBMIT": {
  
          // INSERT new article
          if (articolo1.getId() == 0) {
  
              try {
                  daoArt.insert(articolo1);
                  System.out.println("new article was created");
                  return "redirect:/admin?insert";
  
              } catch (Exception  e) {
                  System.out.println("failed to create new article");
                  e.printStackTrace();
              }
          }
  
          // UPDATE article
          else {
  
              try {
                  daoArt.update(articolo1);
                  System.out.println("article was updated");
                  return "redirect:/admin?update"; 
  
              } catch (Exception  e) {
                  System.out.println("failed to update article");
                  e.printStackTrace();
              }
          }
  
          break;
      }
  
      //DELETE article
      case "DELETE ARTICLE": {
  
          try {
              daoArt.delete(articolo1);
              System.out.println("article was deleted");
              return "redirect:/admin?delete"; 
  
          } catch (Exception  e) {
              System.out.println("failed to delete article");
              e.printStackTrace();
          }
  
          break;
      }
  
      }
  
      return submit;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>JSP</p>
  
  <pre><code>&lt;t:ADMIN&gt;
  &lt;!-- populates the form using the object nea (NewEditArticolo) from servlet ArticleManagerController --&gt;
  &lt;!-- the parameteres are then passed back to the servlet ArticleManagerController --&gt;
  &lt;form:form modelAttribute="nea" action="${pageContext.request.contextPath}/ArticleManager" method="POST"&gt;
  
      &lt;table border="0"&gt;
          &lt;tr&gt;
              &lt;!-- inputs the ID of the article in the cell; if the article was created with ID 0 (new article), the value is 0 --&gt;
              &lt;c:choose&gt;
                  &lt;c:when test="${nea.articolo.id&gt;0}"&gt;
                      &lt;td&gt;Article ID&lt;/td&gt;
                      &lt;td&gt;&lt;form:input path="articolo.id" size="4" placeholder="ID articolo"
                          value="${nea.articolo.id}" readonly="readonly" /&gt;&lt;/td&gt;
                  &lt;/c:when&gt;
                  &lt;c:otherwise&gt;
                      &lt;td&gt;Article ID&lt;/td&gt;
                      &lt;td&gt;&lt;form:input path="articolo.id" size="4" placeholder="ID articolo"
                          value="0" readonly="readonly" /&gt;&lt;/td&gt;
                  &lt;/c:otherwise&gt;
              &lt;/c:choose&gt;
              &lt;td&gt;&lt;form:errors path="articolo.id"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;Restaurant&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="articolo.ristorante" size="50"
                  placeholder="Insert restaurant name"
                  value="${nea.articolo.ristorante}" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:errors path="articolo.id"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;label&gt;Location&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:select path="articolo.IDArea"&gt;
                      &lt;!-- for each object in nea.listArea, checks the ID and adds the name to the select menu
                      if the ID of object in listArea matches the IDArea of the article, it is set as selected --&gt;
                      &lt;c:forEach var="area" items="${nea.listaArea}"&gt;
                          &lt;c:choose&gt;
                              &lt;c:when test="${area.ID==nea.articolo.IDArea}"&gt;
                                  &lt;form:option value="${area.ID}" selected="selected"&gt;
                                      ${area.nome}&lt;/form:option&gt;&gt;
                              &lt;/c:when&gt;
                              &lt;c:otherwise&gt;
                                  &lt;form:option value="${area.ID}"&gt;${area.nome}&lt;/form:option&gt;&gt;
                              &lt;/c:otherwise&gt;
                          &lt;/c:choose&gt;
                      &lt;/c:forEach&gt;
              &lt;/form:select&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:errors path="articolo.IDArea"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;!-- for each object in nea.listCucina, checks the ID and adds the name to the select menu
          if the ID of object in listCucina matches the IDCucina of the article, it is set as selected --&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;label&gt; Cuisine&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:select path="articolo.IDCucina"&gt;
                      &lt;c:forEach var="cucina" items="${nea.listaCucina}"&gt;
                          &lt;c:choose&gt;
                              &lt;c:when test="${cucina.ID==nea.articolo.IDCucina}"&gt;
                                  &lt;form:option value="${cucina.ID}" selected="selected"&gt;
                                      ${cucina.nome}&lt;/form:option&gt;
                              &lt;/c:when&gt;
                              &lt;c:otherwise&gt;
                                  &lt;form:option value="${cucina.ID}"&gt;${cucina.nome}&lt;/form:option&gt;
                              &lt;/c:otherwise&gt;
                          &lt;/c:choose&gt;
                      &lt;/c:forEach&gt;
              &lt;/form:select&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:errors path="articolo.IDCucina"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;!-- for each object in nea.listPrezzo, checks the ID and adds the name to the select menu
          if the ID of object in listPrezzo matches the IDPrezzo of the article, it is set as selected --&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;label&gt; Price &lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:select path="articolo.IDPrezzo"&gt;
                      &lt;c:forEach var="prezzo" items="${nea.listaPrezzo}"&gt;
                          &lt;c:choose&gt;
                              &lt;c:when test="${prezzo.ID==nea.articolo.IDPrezzo}"&gt;
                                  &lt;form:option name="IDPrezzo" value="${prezzo.ID}"
                                      selected="selected"&gt;${prezzo.nome}&lt;/form:option&gt;
                              &lt;/c:when&gt;
                              &lt;c:otherwise&gt;
                                  &lt;form:option name="IDPrezzo" value="${prezzo.ID}"&gt;
                                      ${prezzo.nome}&lt;/form:option&gt;
                              &lt;/c:otherwise&gt;
                          &lt;/c:choose&gt;
                      &lt;/c:forEach&gt;
              &lt;/form:select&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:errors path="articolo.IDPrezzo"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;Website&lt;/td&gt;
              &lt;td&gt;&lt;input name="website" size="50"
                  placeholder="insert website address"}&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;Article date&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="articolo.data" placeholder="aaaa/mm/dd" size="12"
                  value="${nea.articolo.data}"&gt;&lt;/form:input&gt;
                  &lt;td&gt;&lt;form:errors path="articolo.data"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  
      &lt;!-- textbox --&gt;
      &lt;form:textarea path="articolo.articolo"/&gt;
      &lt;td&gt;&lt;form:errors path="articolo.articolo"/&gt;&lt;/td&gt;
  
      &lt;table border="0"&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;label&gt; Stars &lt;/label&gt;&lt;/td&gt;
  
              &lt;!-- for each object in nea.listVoto, checks the ID and adds the name to the select menu --&gt;
              &lt;!-- if the ID of the object in listVoto matches the IDVoto of the article, it is set as selected --&gt;
              &lt;td&gt; &lt;form:select path="articolo.IDVoto"&gt;
                      &lt;c:forEach var="voto" items="${nea.listaVoto}"&gt;
                          &lt;c:choose&gt;
                              &lt;c:when test="${voto.ID==nea.articolo.IDVoto}"&gt;
                                  &lt;form:option value="${voto.ID}" selected="selected"&gt;
                                      ${voto.nome}&lt;/form:option&gt;&gt;
                              &lt;/c:when&gt;
                              &lt;c:otherwise&gt;
                                  &lt;form:option value="${voto.ID}"&gt;${voto.nome}&lt;/form:option&gt;
                              &lt;/c:otherwise&gt;
                          &lt;/c:choose&gt;
                      &lt;/c:forEach&gt;
              &lt;/form:select&gt; &lt;/td&gt;
  
              &lt;td&gt;&lt;form:errors path="articolo.IDVoto"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;label&gt;Picture&lt;/label&gt;&lt;/td&gt;
  
              &lt;td&gt;&lt;form:select path="articolo.foto"&gt;
                      &lt;c:forEach var="img" items="${nea.listaImg}"&gt;
                          &lt;c:choose&gt;
                              &lt;c:when test="${img==nea.articolo.foto}"&gt;
                                  &lt;form:option value="img" selected="selected"&gt;${img}&lt;/form:option&gt;
                              &lt;/c:when&gt;
                              &lt;c:otherwise&gt;
                                  &lt;form:option value="img"&gt;${img}&lt;/form:option&gt;
                              &lt;/c:otherwise&gt;
                          &lt;/c:choose&gt;
                      &lt;/c:forEach&gt;
              &lt;/form:select&gt;&lt;/td&gt;
  
              &lt;td&gt;&lt;form:errors path="articolo.foto"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;label&gt;CURRENT PICTURE&lt;/label&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;img
                  src="${pageContext.request.contextPath}/resources/img/${nea.articolo.foto}"
                  alt="no picture" height=150 width=300&gt;&lt;/img&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;input type="submit" value="SUBMIT" name="submit"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;input type="submit" value="DELETE ARTICLE" name="submit"&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form:form&gt;
  
  &lt;!-- button BACK moves back to view admin.jsp--&gt;
  &lt;form action="${pageContext.request.contextPath}/admin"&gt;
  &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;input type="submit" value="BACK"&gt;&lt;/td&gt;
          &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p></p>
  
  <p>Error message (in this case, I tried to update an article leaving the ristorante field empty)</p>
  
  <pre><code>javax.validation.ConstraintViolationException: Validation failed for classes [beans.Articolo] during update time for groups [javax.validation.groups.Default, ]
  List of constraint violations:[
      ConstraintViolationImpl{interpolatedMessage='error', propertyPath=ristorante, rootBeanClass=class beans.Articolo, messageTemplate='error'}
  ]
      at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:140)
      at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreUpdate(BeanValidationEventListener.java:88)
      at org.hibernate.action.internal.EntityUpdateAction.preUpdate(EntityUpdateAction.java:244)
      at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:118)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:582)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:456)
      at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
      at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
      at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1397)
      at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:473)
      at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3133)
      at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2370)
      at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467)
      at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
      at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
      at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:220)
      at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
      at DAO.DAOArticolo.update(DAOArticolo.java:105)
      at controllers.ArticleManagerController.editArticle(ArticleManagerController.java:94)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
      at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
      at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>My POM file:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
    &lt;groupId&gt;SpringMVCBlog&lt;/groupId&gt;
    &lt;artifactId&gt;SpringMVCBlog&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
  
    &lt;build&gt;
      &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.3&lt;/version&gt;
          &lt;configuration&gt;
            &lt;source&gt;1.8&lt;/source&gt;
            &lt;target&gt;1.8&lt;/target&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.6&lt;/version&gt;
          &lt;configuration&gt;
            &lt;warSourceDirectory&gt;WebContent&lt;/warSourceDirectory&gt;
            &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  
   &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;3.8.1&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- spring-context which provides core functionality --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;version&gt;4.2.0.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- The spring-aop module provides an AOP Alliance-compliant aspect-oriented 
          programming implementation allowing you to define --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
          &lt;version&gt;4.2.0.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- The spring-webmvc module (also known as the Web-Servlet module) contains 
          Spring’s model-view-controller (MVC) and REST Web Services implementation 
          for web applications --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
          &lt;version&gt;4.2.0.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- The spring-web module provides basic web-oriented integration features 
          such as multipart file upload functionality and the initialization of the 
          IoC container using Servlet listeners and a web-oriented application context --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
          &lt;version&gt;4.2.0.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- http://mvnrepository.com/artifact/javax.validation/validation-api --&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;!-- validator --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
          &lt;version&gt;5.2.4.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Spring Security --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
          &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
          &lt;version&gt;4.0.3.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
          &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
          &lt;version&gt;4.0.3.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
          &lt;artifactId&gt;spring-security-taglibs&lt;/artifactId&gt;
          &lt;version&gt;4.0.3.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- JSTL --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
          &lt;version&gt;1.2&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- HIBERNATE --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.2.1.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;!-- Java Servlet API --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
          &lt;version&gt;3.1.0&lt;/version&gt;
      &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  
  &lt;/project&gt;
  </code></pre>