jsp - Sprinboot webapp doesn't load webjars and css
问题描述
I have maven webapp with springboot and jsp. I'm trying to import webjars to use bootstrap on my jsp, I add the dependencies on my pom (locator included) and i put the resource handler on my webconfig:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7-1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.30</version>
</dependency>
Now I add the references on my webconfig:
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("/webjars/");
}
}
And than I try to import the jars in my jsp:
<script src="/webjars/jquery/3.1.1/jquery.min.js"></script>
But doesn't work.. I put css inside webapp folder but I cannot link it inside my jsp..
How can I solve this?? Whats wrong?? Thank you all
Ps: I have my jsp in web-inf/jsp/pages and I have add a context path to application.properties (but I think there are some conflict with WebConfig class)
解决方案
add the resourceChain
and set it to false like this :
registry.addResourceHandler("/webjars/**").addResourceLocations("/webjars/").resourceChain(false);
This is apparently not a webjar-locator problem.call to resourceChain()
method should be necessary for configuration of webjar-locator.
推荐阅读
- javascript - 为什么 HTML DOM 事件不会立即影响同一个 DOM 元素?
- react-native - 添加风味后Android构建失败
- c++ - c++函数中Const用法的区别
- elasticsearch - elasticsearch.yml ses 电子邮件配置
- android - Android应用小部件背景形状以编程方式更改颜色不透明度
- zalenium - Windows - zalenium 文件上传
- http-live-streaming - 使用 EXT-X-BYTERANGE 动态生成 m3u8 列表
- ios - 在我的 iPhone 7,8 和 iOS 10,11 中从 Xcode 9.4 运行我的应用程序时,我在控制台中得到了一些这些打印
- python - 带散景的简单金字塔 hbar 图表
- flutter - 如何从其他 StatefulWidget 更新 StatefulWidget?