title: Spring Boot, Thymeleaf and @Controller
body: <p>I am playing around with Spring Boot and have something that I don't quite get. I have 2 <code>@Controller</code>s in my application, and the second one is not really picking up REST calls, Thymeleaf is jumping on the requests instead.</p>
  
  <p>Basically what I have is:</p>
  
  <pre><code>@Configuration
  @ComponentScan
  @EnableAutoConfiguration
  public class Application {
       public static void main(String[] args) throws Throwable {
              SpringApplication.run(Application.class, args);
       }
  }
  </code></pre>
  
  <p>Then</p>
  
  <pre><code>@Configuration
  @EnableWebMvcSecurity
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(prePostEnabled=true)
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      Environment env;
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests()
            .antMatchers("/", "/home").permitAll()
            .antMatchers("/webjars/**").permitAll()
            .antMatchers("/console/**").permitAll()
            .antMatchers("/resources/**").permitAll()
            .anyRequest().authenticated();
          http.formLogin().loginPage("/login").permitAll().and().logout()
                  .permitAll();
          http.csrf().disable(); // for angularjs ease
          http.headers().frameOptions().disable(); //for H2 web console
      }
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>@Configuration
  public class WebMvcConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addViewControllers(ViewControllerRegistry registry) {
          registry.addViewController("/home").setViewName("home");
          registry.addViewController("/").setViewName("home");
          registry.addViewController("/hello").setViewName("hello");
          registry.addViewController("/login").setViewName("login");
      }
  
      @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/public/**").addResourceLocations("classpath:/public/");
          registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/");
        }
  
  }
  </code></pre>
  
  <p>And the two controllers. This one works, so it is picking up my call from a simple AngularJS client and responds:</p>
  
  <pre><code>@Controller
  @RequestMapping("/foo")
  public class MyController {
  
      @RequestMapping(method = RequestMethod.GET)
      @ResponseBody
      @PreAuthorize("hasRole('ROLE_FOO')")
      public String getFoo() {
          return "foooooo";
      }
  }
  </code></pre>
  
  <p>And this is the sick controller, not responding:</p>
  
  <pre><code>@Controller
  @RequestMapping("/sick/1")
  public class SickController {
  
      @Autowired
      SickRepository sickRepository;
  
      @RequestMapping(method = RequestMethod.GET)
      public Sick getSickById() {
          return sickRepository.findOne(1);
      }
  
  }
  </code></pre>
  
  <p>Obviously later I'll change it to pull the ID from the URL as a path variable, but for debugging I went back to hardcoding.</p>
  
  <p>The logs don't show anything until my request to <code>/sick/1</code> arrive. At that point I am getting this:</p>
  
  <pre><code>org.thymeleaf.exceptions.TemplateInputException: Error resolving template "sick/1", template might not exist or might not be accessible by any of the configured Template Resolvers
      at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:245)
      at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104)
  </code></pre>
  
  <p>But why does it go to the template engine instead of my controller..?</p>