[英]Spring Webjars locator and context-path
I have Spring Boot application with enabled Spring Security configured like this: 我有Spring Boot应用程序,启用了Spring Security,配置如下:
@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();
}
Everything works fine until I change context-path. 一切正常,直到我改变上下文路径。 For example, if I set the it like this:
例如,如果我将它设置为:
server:
context-path: /myapp
I cant access my webjars, css... They are still looked at: http://localhost:8080/webjars/ ... 我无法访问我的webjars,css ......他们仍然看着: http:// localhost:8080 / webjars / ...
How can I configure Spring Webjars so that it works regardless of context-path? 如何配置Spring Webjars以使其无论上下文路径如何都可以工作?
OK, I solved the problem. 好的,我解决了这个问题。
What I forget to do is request Thymeleaf engine to process relative paths of my CSS and js files. 我忘记做的是请求Thymeleaf引擎处理我的CSS和js文件的相对路径。 So, basically I changed this in my template:
所以,基本上我在模板中更改了这个:
<link rel="stylesheet" type="text/css" href="/webjars/bootstrap/css/bootstrap.min.css" />
to this: 对此:
<link rel="stylesheet" type="text/css" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.