Spring Webjars Locator and Context Path

I have a Spring boot application with Spring Security enabled, configured as follows:

    @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 the context path. For example, if I asked it like this:

server:
   context-path: /myapp

I cannot access my webjars, css ... They are still looking at: http: // localhost: 8080 / webjars / ...

How to configure Spring Webjars so that it works regardless of the context path?

+4
source share
1 answer

Ok, I solved the problem.

, 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}" />
+4

All Articles