根据docs为静态资源位置注册src/main/resources/static、src/main/resources/public、src/main/resources/resources等。
我得到了
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");
}
}我得到了
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>在警察那里。
发布于 2014-04-21 17:52:25
@EnableWebMvc的显式声明禁止Spring对Web的自动配置。
如果不想启用自动配置,可以从WebMvcConfig中删除它以启用自动配置,或者在addResourceHandlers()中手动为静态内容添加资源处理程序。
https://stackoverflow.com/questions/23202607
复制相似问题