根據文檔Spring Boot寄存器src/main/resources/static
,src/main/resources/public
,src/main/resources/resources
等查找靜態資源位置。Spring Boot Web靜態資源
我
src/main/resources
-static
-js
-stomp.js
,並在HTML(放置在模板文件夾):
<script type="text/javascript" th:src="@{/js/stomp.js}"></script>
但我得到了404的腳本(GET http://localhost:8080/js/stomp.js 404 (Not Found)
)。我做錯了什麼?
我也試過
<script type="text/javascript" src="../static/js/stomp.js"></script>
和
<script type="text/javascript" src="/js/stomp.js"></script>
具有相同的結果。
我的MVC配置(僅一個視圖 - 控制器):
@EnableWebMvc
@ComponentScan(basePackages = {"controller"})
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/sock").setViewName("/index");
}
}
和i。在POM得到
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
。
http://stackoverflow.com/questions/17312034/cant-find-css-images-and-js-static-files-in-spring – Thunda