Cod*_*mer 3 jsp web-applications webjars spring-boot
我有一个带有 Spring Boot 和 JSP 的 Maven Web 应用程序。我正在尝试导入 webjar 以在 JSP 上使用 bootstrap,我添加了对我的 pom 的依赖项(包括定位器),并将资源处理程序放在我的 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>
Run Code Online (Sandbox Code Playgroud)
现在我在我的 webconfig 上添加引用:
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("/webjars/");
}
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试将 jar 导入我的 JSP 中:
<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>
Run Code Online (Sandbox Code Playgroud)
但这不起作用。我将 css 放入 webapp 文件夹中,但无法将其链接到 JSP 中。
我该如何解决这个问题?怎么了?
PS:我有我的JSP,web-inf/jsp/pages并且添加了上下文路径application.properties(但我认为与该类存在一些冲突WebConfig)。
添加resourceChain并将其设置为 false,如下所示:
registry.addResourceHandler("/webjars/**").addResourceLocations("/webjars/").resourceChain(false);
Run Code Online (Sandbox Code Playgroud)
这显然不是 webjar 定位器问题。resourceChain()配置 webjar 定位器应该需要调用方法。
| 归档时间: |
|
| 查看次数: |
4973 次 |
| 最近记录: |