title: Spring boot - why can't my application find static resources?
body: <p>I am giving Spring Boot a go and can't access CSS, images and JS files. </p>
  
  <p>I've this @SpringBootApplication class:</p>
  
  <pre><code>@SpringBootApplication
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>My <code>application.properties</code> file reads:</p>
  
  <pre><code>spring.datasource.url=jdbc:mysql://localhost:3306/&lt;schema&gt;?autoReconnect=true&amp;useSSL=false
  spring.datasource.driverClassName=com.mysql.jdbc.Driver
  spring.datasource.name=&lt;sql-databasename&gt;
  spring.datasource.username=&lt;sql-username&gt;
  spring.datasource.password=&lt;sql-password&gt;
  #spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  spring.jpa.database=MYSQL
  spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
  spring.jpa.show-sql=false 
  spring.jpa.hibernate.ddl-auto=update
  
  # EMBEDDED SERVER CONFIGURATION (ServerProperties)
  server.context-path=/&lt;application-name&gt;
  server.display-name=&lt;application-name&gt;
  server.port=8080
  server.session.cookie.max-age=3600
  
  # SPRING MVC (WebMvcProperties)
  spring.mvc.favicon.enabled=true
  spring.mvc.date-format=dd/MM/yyyy
  spring.mvc.locale=pt_BR
  spring.mvc.locale-resolver=accept-header
  spring.mvc.servlet.load-on-startup=-1
  spring.mvc.static-path-pattern=/**
  
  # SPRING RESOURCES HANDLING (ResourceProperties)
  spring.resources.add-mappings=true
  spring.resources.cache-period=1
  spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/**,classpath:/public/**
  
  # THYMELEAF (ThymeleafAutoConfiguration)
  spring.thymeleaf.cache=true
  spring.thymeleaf.check-template-location=true
  spring.thymeleaf.prefix=classpath:/templates/
  spring.thymeleaf.suffix=.html
  spring.thymeleaf.mode=HTML5
  spring.thymeleaf.encoding=UTF-8
  spring.thymeleaf.content-type=text/html
  </code></pre>
  
  <p>Purely by still not fully understanding how Spring Boot works, I haven't been able to shake this configuration file off:</p>
  
  <pre><code>@Configuration
  @EnableAutoConfiguration
  @ComponentScan(basePackages = "b.c.g.c")
  public class CmsBootApplicationConfiguration extends WebMvcConfigurerAdapter {
  
      @Bean(name = "messageSource")
      @Description("Spring message resolver")
      public MessageSource messageSource() {
          ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
          messageSource.setBasename("i18n/messages");
          messageSource.setFallbackToSystemLocale(false);
          messageSource.setCacheSeconds(0);
          messageSource.setDefaultEncoding("utf-8");
          return messageSource;
      }
  
      @Bean(name = "localeResolver")
      @Description("Spring locale resolver")
      public LocaleResolver localeResolver() {
          SessionLocaleResolver resolver = new SessionLocaleResolver();
          resolver.setDefaultLocale(new Locale("pt", "BR"));
          return resolver;
      }
  
      @Bean(name = "multipartResolver")
      public StandardServletMultipartResolver resolver() {
          return new StandardServletMultipartResolver();
      }
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("classpath:/resources/**").addResourceLocations("/resources/");
      }
  
      @Bean
      public UrlTemplateResolver urlTemplateResolver() {
          return new UrlTemplateResolver();
      }
  }
  </code></pre>
  
  <p>Static resources are located here:</p>
  
  <pre><code>src/main/resources
      static
          css/
          img/
          js/
  </code></pre>
  
  <p>But, when I try to access any static resource like, like, for instance on the browser call bellow:</p>
  
  <p><code>http://localhost:8080/&lt;application-name&gt;/static/css/bootstrap.min.css</code></p>
  
  <p>The result is:</p>
  
  <p>{"timestamp":1472734923645,"status":404,"error":"Not Found","message":"No message available","path":"/cms/static/css/bootstrap.min.css"}</p>
  
  <p>But the file <strong>is</strong> there...</p>
  
  <p>I glanced through but couldn't find the solution at the <a href="http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/pdf/spring-boot-reference.pdf" rel="nofollow">Spring Boot Reference Guide</a>.</p>
  
  <p>What am I doing wrong and how to get it working?</p>