title: Wildfly 8 Final Null ModelAndView returned to DispatcherServlet with name 'dispatcher'
body: <p>I am using Wildfly 8 Final, a WebApplicationInitializer implementation instead of a web.xml, Spring MVC 4 and Spring Security 3.2. The problem I have is that even though Wildfly says it has deployed the war successfully sometimes (not all the times) when I try to access any URI of the web app I get &quot;404 Not Found&quot;. The problem remains until I redeploy the web app. Emptying the tmp folder does not matter-the error might still be there after restart.</p>
  <p>I turned debug on and the only thing out of the ordinary is &quot;Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling&quot; (after a request). The thing is that I get this message in both situations.</p>
  <p>Here is my WebApplicationInitializer</p>
  <pre><code>public class MyWebAppInitializer implements WebApplicationInitializer {
  
  @Override
  public void onStartup(ServletContext servletContext)
          throws ServletException {
      AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
      dispatcherServlet.register(WebConfig.class, SecurityConfig.class,
              DataConfig.class);
  
      servletContext
              .addListener(new ContextLoaderListener(dispatcherServlet));
  
      servletContext.setInitParameter(&quot;defaultHtmlEscape&quot;, &quot;true&quot;);
  
      servletContext.addListener(new HttpSessionEventPublisher());    
      
       FilterRegistration.Dynamic fr = servletContext.addFilter(&quot;encodingFilter&quot;,  
                new CharacterEncodingFilter());
             fr.setInitParameter(&quot;encoding&quot;, &quot;UTF-8&quot;);
             fr.setInitParameter(&quot;forceEncoding&quot;, &quot;true&quot;);
             fr.addMappingForUrlPatterns(null, true, &quot;/*&quot;);
      
      servletContext.addFilter(&quot;springSecurityFilterChain&quot;,
              DelegatingFilterProxy.class).addMappingForUrlPatterns(null,
              false, &quot;/*&quot;);
  
      ServletRegistration.Dynamic dispatcher = servletContext.addServlet(
              &quot;dispatcher&quot;, new DispatcherServlet(dispatcherServlet));
      dispatcher.setLoadOnStartup(1);
      dispatcher.addMapping(&quot;/&quot;);
  }}
  </code></pre>
  <p>and here is the security config:</p>
  <pre><code>public class SecurityConfig {
  @Configuration
  @Order(1)
  public static class SecurityConfigForRest extends
          WebSecurityConfigurerAdapter {
  
      @Autowired
      TokenAuthenticationProvider tokenAuthenticationProvider;
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth)
              throws Exception {
          auth.authenticationProvider(tokenAuthenticationProvider);
      }
  
      @Bean
      @Override
      public AuthenticationManager authenticationManagerBean()
              throws Exception {
          return super.authenticationManagerBean();
      }
  
      @Bean
      protected TokenAuthenticationFilter getTokenAuthFilter()
              throws Exception {
          TokenAuthenticationFilter tapf = new TokenAuthenticationFilter(
                  authenticationManagerBean());
          return tapf;
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
  
          http.requestMatchers()
                  .antMatchers(&quot;/rest/set/**&quot;,
                          &quot;/rest/get/**&quot;)
                  .and()
                  .addFilterBefore(getTokenAuthFilter(),
                          AbstractPreAuthenticatedProcessingFilter.class)
                  .csrf().disable();
  
      }
  }
  
  @Configuration
  @Order(2)
  public static class SecurityConfigForWebApp extends
          WebSecurityConfigurerAdapter {
  
      @Autowired
      UserDetailsService userDetailsService;
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth)
              throws Exception {
          auth.userDetailsService(userDetailsService).passwordEncoder(
                  passwordEncoder());
      }
  
      @Bean
      public PasswordEncoder passwordEncoder() {
          return new BCryptPasswordEncoder();
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests()
                  .antMatchers(&quot;/&quot;, &quot;/index&quot;, &quot;/forgotPassword&quot;).permitAll()
                  .antMatchers(&quot;/sysadmin/*&quot;).hasAnyRole(&quot;SYS_ADMIN&quot;)
                  .antMatchers(&quot;/admin/*&quot;)
                  .hasAnyRole(&quot;SYS_ADMIN&quot;, &quot;ADMIN&quot;)
                  .antMatchers(&quot;/user/*&quot;)
                  .hasAnyRole(&quot;SYS_ADMIN&quot;, &quot;ADMIN&quot;, &quot;USER&quot;)
                  .and().formLogin().loginPage(&quot;/login&quot;)
                  .loginProcessingUrl(&quot;/login&quot;).permitAll()
                  .defaultSuccessUrl(&quot;/index&quot;)
                  .successHandler(new SecurityLoginSuccessHandler()).and()
                  .sessionManagement().maximumSessions(1)
                  .expiredUrl(&quot;/sessionExpired&quot;).and().and()
                  .exceptionHandling()
                  .accessDeniedHandler(new SecurityAccessDeniedHandler())
                  .and().logout().logoutSuccessUrl(&quot;/login&quot;)
                  .invalidateHttpSession(true).deleteCookies(&quot;JSESSIONID&quot;);
  
      }
  
      @Override
      public void configure(WebSecurity web) throws Exception {
          web.ignoring().antMatchers(&quot;/resources/**&quot;);
      }
  }}
  </code></pre>
  <p>It really does not make much sense how sometimes it works OK and others it does not.</p>
  <h1>Edit</h1>
  <p><a href="http://pastebin.com/uieCcsLB" rel="nofollow noreferrer">Not found log</a>/Spring Security On</p>
  <p><a href="http://pastebin.com/38sH9Tfb" rel="nofollow noreferrer">Normal response</a>/(Spring Security On)</p>
  <p><a href="http://pastebin.com/2XsAwhjL" rel="nofollow noreferrer">Normal response</a>/(Spring Secutiry Off)</p>