我有一个来自start.spring.io的新春项目
我创建了文件project/src/main/resources/js/a.js
我也创造了project/src/main/resources/templates/index.html
(与百里香一起)
需要a.js
<script th:src="@{/js/a.js}"></script>
我也有以下配置:
@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/js/**")
.addResourceLocations("/js/");
}
}
当应用程序启动时,我可以在日志中看到:
Mapped URL path [/js/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
.addResourceLocations();
我尝试了各种变体,例如:
"/resources/js"
,"resources/js"
,"/js"
,"js"
application.properties
使用spring.resources.static-locations=classpath:/resources/
/resources/static/js/a.js
并相应地更新addResourceLocatios
参数有什么想法吗?