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?
A ResourceResolver that delegates to the chain to locate a resource and then attempts to find a matching versioned resource contained in a WebJar JAR file. This allows WebJars.org users to write version agnostic paths in their templates, like <script src="/jquery/jquery. min. js"/> .
WebJars are client-side web libraries (e.g. jQuery & Bootstrap) packaged into JAR (Java Archive) files. Explicitly and easily manage the client-side dependencies in JVM-based web applications. Use JVM-based build tools (e.g. Maven, Gradle, sbt, ...) to download your client-side dependencies.
Spring Boot is an open source Java-based framework used to create a micro Service. It is developed by Pivotal Team and is used to build stand-alone and production ready spring applications.
The Spring Framework (Spring) is an open-source application framework that provides infrastructure support for developing Java applications. One of the most popular Java Enterprise Edition (Java EE) frameworks, Spring helps developers create high performing applications using plain old Java objects (POJOs).
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}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With