2016-11-15 2 views
0

내가 Thymeleaf 봄 부팅, 봄 보안에 응용 프로그램을 작성하고 내가 액세스 내 정적 리소스 파일을 얻으려고 ...봄 부팅 보안 정적 리소스

. 
    ├── 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 
난 왜 항상 404 오류가 사용 태그를

 <img src="/praca.jpg" alt="sd"/> 

을 시도 어디 템플릿/index.html을에서 HTML 파일이

? 내가 뭔가 잘못한 곳 ??

내 일반 초기화 클래스 :

@SpringBootApplication 
    public class Application extends WebMvcConfigurerAdapter { 

     public static void main(String[] args) { 
      SpringApplication.run(InzynierkaApplication.class, args); 
     } 
    } 

내 보안 클래스 : 템플릿에서

@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); 
     } 

    } 
+0

확인을 위해 전체 페이지가 404 또는 이미지 자산 만 반환합니까? –

+0

404 이미지 애셋 만 반환합니다. 다른 내용이 성공적으로로드됩니다. – technics

답변

1

당신이 자신에 의해 자동으로 컨텍스트를 추가 할 thymeleaf 형식을 사용해야합니다. 이 옵션을 사용합니다 :

<img th:src="@{/praca.jpg}" alt="sd"/> 

/praca.jpg

나는 비슷한 문제를 가지고하고 문제

+0

그것은 나를 위해 일하지 않습니다. – technics

0

정적 또는 공용 폴더에서 이미지의 전체 경로해야했다 스프링 보안 따라서이 문제가있는 사용자는 인증이 필요없는 URL 목록에 정적 파일이있는 폴더를 추가 할 수 있습니다. 예 : antMatchers("/css/**", "/fonts/**").permitAll()