title: spring boot security static resources
body: <p>I write app in Spring Boot, Spring Security with Thymeleaf and I try to get access my static resource file...</p>
  
  <p>This is my project structure...</p>
  
  <pre><code>    .
      ├── mvnw
      ├── mvnw.cmd
      ├── nb-configuration.xml
      ├── pom.xml
      ├── src
      │   ├── main
      │   │   ├── java
      │   │   │   └── com
      │   │   ├── resources
      │   │   │   ├── application.properties
      │   │   │   ├── static
      |   |   |   |    |---------------------------------this is image.jpg
      │   │   │   ├── templates
      │   │   │   └── ValidationMessages.properties
      │   │   └── wro
      │   │       ├── css
      │   │       ├── fonts
      │   │       ├── js
      │   │       ├── scss
      │   │       ├── wro.properties
      │   │       └── wro.xml
      │   └── test
      │       └── java
      │           └── com
  </code></pre>
  
  <p>I have HTML file in templates/index.html where i try use tag</p>
  
  <pre><code>     &lt;img src="/praca.jpg" alt="sd"/&gt;
  </code></pre>
  
  <p>Why I always get 404 error ? Where I do something wrong ??</p>
  
  <p>My general init class:</p>
  
  <pre><code>    @SpringBootApplication
      public class Application extends WebMvcConfigurerAdapter {
  
          public static void main(String[] args) {
              SpringApplication.run(InzynierkaApplication.class, args);
          }
      }
  </code></pre>
  
  <p>My security class:</p>
  
  <pre><code>    @Configuration
      public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  
          @Autowired
          private UserAuthenticationDetails userAuthenticationDetails;
  
          @Override
          protected void configure(AuthenticationManagerBuilder auth) throws Exception {
              auth.userDetailsService(userAuthenticationDetails);
              auth.authenticationProvider(authenticationProvider());
          }
  
          @Bean
          public PasswordEncoder passwordEncoder() {
              return new BCryptPasswordEncoder();
          }
  
          @Bean
          public DaoAuthenticationProvider authenticationProvider() {
              DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
              authenticationProvider.setUserDetailsService(userAuthenticationDetails);
              authenticationProvider.setPasswordEncoder(passwordEncoder());
              return authenticationProvider;
          }
  
          @Override
          protected void configure(HttpSecurity http) throws Exception {
              http.csrf().disable()
                      .authorizeRequests()
                      .antMatchers("/","/login").permitAll()
                      .anyRequest().authenticated()
                      .and()
                      .formLogin()
                      .loginPage("/login")
                      .usernameParameter("username")
                      .passwordParameter("password")
                      .defaultSuccessUrl("/",true)
                      .and()
                      .logout()
                      .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                      .logoutUrl("/logout")
                      .logoutSuccessUrl("/login?logout")
                      .invalidateHttpSession(true);
          }
  
      }
  </code></pre>