P
P
postya2020-03-30 20:57:28
Spring
postya, 2020-03-30 20:57:28

Why are images from static resources not displayed?

For some reason, the application on Spring Boot + Thymeleaf + Spring Security

does not display images in html. In the browser developer tools, the picture is highlighted in red, and the type of this file is generally shown as json, although this is a regular png

picture I tried different images, it does not help

How can this be fixed?

HTML:

<div class="info-icon">
            <img th:src="@{/images/download.png}" alt="download">
</div>


Spring Security File:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/").permitAll();
    }

}


File structure:

5e8232672a1aa893574353.jpeg

Browser:

5e8232e923316548977472.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2020-03-31
@postya

Stop!

So the image is not displayed. 404 error in console.

The solution is Build Project (ctrl + F9) or Rebuild Project and Spring will see your new static and everything will work.
+ if you use Spring Security, then:
@Override
        public void configure(WebSecurity web) {
            web.ignoring().antMatchers(

                    // статика
                    "/css/**",
                    "/js/**",
                    "/fonts/**",
                    "/images/**"
            );
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question