Reputation: 22496
According to the docs Spring Boot registers src/main/resources/static
, src/main/resources/public
, src/main/resources/resources
, etc. for static resources locations.
I got
src/main/resources
-static
-js
-stomp.js
and in the html(placed in templates folder):
<script type="text/javascript" th:src="@{/js/stomp.js}"></script>
but I got 404 for the script(GET http://localhost:8080/js/stomp.js 404 (Not Found)
). What I do wrong?
I also tried
<script type="text/javascript" src="../static/js/stomp.js"></script>
and
<script type="text/javascript" src="/js/stomp.js"></script>
with the same result.
My mvc configuration(just one view-controller):
@EnableWebMvc
@ComponentScan(basePackages = {"controller"})
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/sock").setViewName("/index");
}
}
and i got
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
in the POM.
Upvotes: 1
Views: 893
Reputation: 242686
Explicit declaration of @EnableWebMvc
disables Spring Boot's autoconfiguration for Web MVC.
Either remove it from your WebMvcConfig
to enable autoconfiguration, or add resource handlers for static content manually in addResourceHandlers()
if you don't want to enable autoconfiguration.
Upvotes: 7