I want to make page using thymeleaf
. But I have some problem with the static files. I've investigated questions(1,2,3) with similar problem, but it didn't help me.
I use Spring Boot
framework in the application.
My files look like:
test.html
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<script src="js/test.js" th:src="@{/test.js}"/>
</head>
<body>
<button onclick="testFunction('test value')">Button</button>
</body>
</html>
test.js
function testFunction(test) {
console.log(test);
}
Configuration class
@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/js/");
super.addResourceHandlers(registry);
}
}
And problem, when I load test.html
file with javascript not loaded.
@GetMapping(value = "web/test")
public String getTestHtmlPage() {
return "test";
}
/api/v1
is a configuration in application.properties => server.servlet-path=/api/v1
What do I do wrong? Can you help me?
Thanks all!