title: Load static resource in Spring Boot with Thymeleaf
body: <p>I want to make page using <code>thymeleaf</code>. But I have some problem with the static files. I've investigated questions(<a href="https://stackoverflow.com/questions/27869267/loading-static-resources-with-spring-boot-and-thymeleaf">1</a>,<a href="https://stackoverflow.com/questions/35541839/static-resources-using-spring-and-thymeleaf">2</a>,<a href="https://stackoverflow.com/questions/29918732/not-loading-static-resources-in-spring-boot-thymeleaf-and-angularjs-app">3</a>) with similar problem, but it didn't help me.</p>
  
  <p>I use <code>Spring Boot</code> framework in the application.
  My files look like:
  <a href="https://i.stack.imgur.com/ZFTm8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZFTm8.png" alt="enter image description here"></a></p>
  
  <p><strong>test.html</strong></p>
  
  <pre><code>&lt;html lang="en" xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
      &lt;script src="js/test.js" th:src="@{/test.js}"/&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;button onclick="testFunction('test value')"&gt;Button&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>test.js</strong></p>
  
  <pre><code>function testFunction(test) {
      console.log(test);
  }
  </code></pre>
  
  <p><strong>Configuration class</strong></p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  public class WebMvcConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/**").addResourceLocations("classpath:/static/js/");
          super.addResourceHandlers(registry);
      }
  }
  </code></pre>
  
  <p>And problem, when I load <code>test.html</code> file with javascript not loaded.</p>
  
  <pre><code>@GetMapping(value = "web/test")
  public String getTestHtmlPage() {
      return "test";
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RfdZK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RfdZK.png" alt="enter image description here"></a></p>
  
  <p><code>/api/v1</code> is a configuration in <code>application.properties =&gt; server.servlet-path=/api/v1</code></p>
  
  <p>What do I do wrong? Can you help me?</p>
  
  <p>Thanks all!</p>