Reputation: 1425
I have Spring Boot application with enabled Spring Security configured like this:
@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/...
How can I configure Spring Webjars so that it works regardless of context-path?
Upvotes: 5
Views: 4110
Reputation: 1425
OK, I solved the problem.
What I forget to do is request Thymeleaf engine to process relative paths of my CSS and js files. 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}" />
Upvotes: 6