gpt4 book ai didi

java - Spring Webjars 定位器和上下文路径

转载 作者:搜寻专家 更新时间:2023-11-01 02:22:36 25 4
gpt4 key购买 nike

我有一个启用了 Spring Security 的 Spring Boot 应用程序,配置如下:

    @Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/home", "/webjars/**", "/css/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}

在我更改上下文路径之前一切正常。例如,如果我这样设置它:

server:
context-path: /myapp

我无法访问我的 webjars、css...它们仍在查看:http://localhost:8080/webjars/ ...

我如何配置 Spring Webjars 使其在不受上下文路径影响的情况下工作?

最佳答案

好的,我解决了这个问题。

我忘记做的是请求 Thymeleaf 引擎处理我的 CSS 和 js 文件的相对路径。所以,基本上我在我的模板中改变了这个:

<link rel="stylesheet" type="text/css" href="/webjars/bootstrap/css/bootstrap.min.css" />

为此:

<link rel="stylesheet" type="text/css" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}" />

关于java - Spring Webjars 定位器和上下文路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35768043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com