title: Spring Security NoClassDefFoundError
body: <p>Working on a Spring project and am learning to use Spring Security.
  The project was working but has suddenly decided no to. Can anyone shed some light as to why?</p>
  
  <p>WebInit.java
  <div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.catalyst.Config;
  
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRegistration.Dynamic;
  
  import org.springframework.web.WebApplicationInitializer;
  import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
  import org.springframework.web.servlet.DispatcherServlet;
  
  public class WebInit implements WebApplicationInitializer
  {
      @Override
      public void onStartup(ServletContext servletContext) throws ServletException
      {
          Dynamic hServlet;
          AnnotationConfigWebApplicationContext hAnnoCTX;
  
          hAnnoCTX = new AnnotationConfigWebApplicationContext();
          hAnnoCTX.register(WebMVCConfig.class);
          hAnnoCTX.setServletContext(servletContext);
          hServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(hAnnoCTX));
          hServlet.addMapping("/");
          hServlet.setLoadOnStartup(1);
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>WebMVCConfig.java
  <div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.catalyst.Config;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  import org.springframework.web.servlet.view.JstlView;
  import org.springframework.web.servlet.view.UrlBasedViewResolver;
  
  @Configuration
  @ComponentScan("com.catalyst")
  @EnableWebMvc
  public class WebMVCConfig extends WebMvcConfigurerAdapter
  {
      @Bean
      public UrlBasedViewResolver setupViewResolver()
      {
          UrlBasedViewResolver hResolver;
          hResolver = new UrlBasedViewResolver();
          hResolver.setPrefix("/WEB-INF/JSP/");
          hResolver.setSuffix(".jsp");
          hResolver.setViewClass(JstlView.class);
          return(hResolver);
      }
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry hRegistry)
      {
          hRegistry.addResourceHandler("/Resources/**").addResourceLocations("/WEB-INF/Resources/*");
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>SpringSecurity.java
  <div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.catalyst.Config;
  
  import org.springframework.context.annotation.Configuration;
  import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  import org.springframework.security.config.annotation.web.builders.WebSecurity;
  import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  
  @Configuration
  @EnableWebSecurity
  public class SpringSecurity extends WebSecurityConfigurerAdapter
  {
      
      @Override
      public void configure(WebSecurity web) throws Exception
      {
          web.ignoring().antMatchers("/", "/Error/**", "/Resources/**");
      }
      
      @Override
      protected void configure(HttpSecurity http) throws Exception
      {
          http
              .authorizeRequests()
              .anyRequest().authenticated()
              .and()
              .formLogin()
                  .loginPage("/Login").and()
              .httpBasic();
      }
      
      @Override
      protected void configure(AuthenticationManagerBuilder auth) throws Exception
      {
          auth
              .inMemoryAuthentication()
              .withUser("user").password("password").roles("USER").and()
              .withUser("admin").password("password").roles("USER", "ADMIN");
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>pom.xml</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &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;com.catalyst&lt;/groupId&gt;
      &lt;artifactId&gt;prjPersonal&lt;/artifactId&gt;
      &lt;version&gt;1.0_Personal&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;name&gt;prjPersonal&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;endorsed.dir&gt;${project.build.directory}/endorsed&lt;/endorsed.dir&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;!-- Versions --&gt;
          &lt;jstl.version&gt;1.2&lt;/jstl.version&gt;
          &lt;mysql.version&gt;5.1.35&lt;/mysql.version&gt;
          &lt;spring.version&gt;4.0.1.RELEASE&lt;/spring.version&gt;
          &lt;hibernate.version&gt;5.0.0.CR1&lt;/hibernate.version&gt;
      &lt;/properties&gt;
      
      &lt;dependencies&gt;
          
          &lt;dependency&gt;
              &lt;groupId&gt;javax&lt;/groupId&gt;
              &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
              &lt;version&gt;7.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          
          &lt;!-- Spring --&gt;
          &lt;dependency&gt;
       &lt;groupId&gt;org.springframework&lt;/groupId&gt;
       &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
       &lt;version&gt;4.1.6.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
   
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
              &lt;version&gt;4.1.6.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
   
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;4.1.6.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
              &lt;version&gt;4.0.1.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.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          
          &lt;!-- JSTL --&gt;
          &lt;dependency&gt;  
              &lt;groupId&gt;jstl&lt;/groupId&gt;  
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;  
              &lt;version&gt;${jstl.version}&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;${hibernate.version}&lt;/version&gt;
          &lt;/dependency&gt;
          
          &lt;!-- MySQL --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;${mysql.version}&lt;/version&gt;
          &lt;/dependency&gt;
          
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                      &lt;compilerArguments&gt;
                          &lt;endorseddirs&gt;${endorsed.dir}&lt;/endorseddirs&gt;
                      &lt;/compilerArguments&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.6&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;validate&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;copy&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;outputDirectory&gt;${endorsed.dir}&lt;/outputDirectory&gt;
                              &lt;silent&gt;true&lt;/silent&gt;
                              &lt;artifactItems&gt;
                                  &lt;artifactItem&gt;
                                      &lt;groupId&gt;javax&lt;/groupId&gt;
                                      &lt;artifactId&gt;javaee-endorsed-api&lt;/artifactId&gt;
                                      &lt;version&gt;7.0&lt;/version&gt;
                                      &lt;type&gt;jar&lt;/type&gt;
                                  &lt;/artifactItem&gt;
                              &lt;/artifactItems&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Tomcat Error
  <div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>HTTP Status 500 - Servlet.init() for servlet dispatcher threw exception
  root cause:
  
  java.lang.NoClassDefFoundError: org/springframework/security/web/access/WebInvocationPrivilegeEvaluator
   java.lang.Class.getDeclaredMethods0(Native Method)
   java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
   java.lang.Class.getDeclaredMethods(Class.java:1975)
   org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:467)
   org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:451)
   org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:512)
   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:663)
   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:593)
   org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1396)
   org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:382)
   org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:353)
   org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:463)
   org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1071)
   org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:277)
   org.springframework.web.servlet.DispatcherServlet.initHandlerMappings(DispatcherServlet.java:549)
   org.springframework.web.servlet.DispatcherServlet.initStrategies(DispatcherServlet.java:463)
   org.springframework.web.servlet.DispatcherServlet.onRefresh(DispatcherServlet.java:452)
   org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:550)
   org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
   org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
   javax.servlet.GenericServlet.init(GenericServlet.java:158)
   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
   org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
   org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
   org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2463)
   org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2452)
   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   java.lang.Thread.run(Thread.java:745)</code></pre>
  </div>
  </div>
  </p>