情况:
我有一个来自 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参数
有任何想法吗?
