1

enter image description here

I want to have access to the login.css file. For that I try to do this in the login page:

<link rel="stylesheet" type="text/css" href="..static/css/login.css" th:href="@{/static/css/login.css}"/>

And I have a WebConfig:

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");

    }
}
2
  • Do you use Spring-Boot? Commented Sep 10, 2018 at 11:55
  • Yes, I use Spring Boot Commented Sep 10, 2018 at 12:00

1 Answer 1

5

Since you use Spring-Boot, the path should be recognized automatically. The project structure should be alike:

  • resources/static/js
  • resources/static/css

In case there are no other overridden methods, remove the WebConfig class with the annotations. I recommend avoiding using the @EnableWebMvc with Spring-Boot since you take all the control (and responsibility) over the MVC configuration.

Access to a static resource with:

<link rel="stylesheet" th:href="@{/css/login.css}"/>
Sign up to request clarification or add additional context in comments.

2 Comments

I did how you told me, but when I try to access the login page, it appears without css style. After authentication I receive localhost:8082/css/login.css, that contains the code from login.css and if I click back I receive the form with css included.
I succed after I added more: antMatchers("/css/**").permitAll()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.