简体   繁体   中英

Spring Webjars locator and context-path

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?

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}" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM