2016-11-21 4 views
0

방금 ​​Spring Security (봄 보안 포함) 및 Thymeleaf 프로젝트를 시작했습니다. 정적 인 리소스를 통합하기를 원했기 때문에 다른 파일 구조를 시도했지만 그 중 아무 것도 사용하지 않았습니다. Spring은 파일을 바인딩했습니다. 정적 리소스 경로를 변경하지 않았기 때문에 내 콘솔은 내 시동시에 Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]을 출력합니다.스프링 부트 Thymeleaf 정적 컨텐츠가로드되지 않음

다른 파일 구조 나는 시도했지만 성공하지 못했습니다.

src 
|--main 
    |--java 
    |--resources 
     |--static 
      |--css 
      |--bootstrap.min.css 
      |--custom_test.css 
      |--templates 
      |--.... 

또한

src 
|--main 
    |--java 
    |--resources 
     |--webjars   
      |--static 
      |--css 
       |--bootstrap.min.css 
       |--custom_test.css 
     |--templates 
      |--.... 

또는 내가

<link rel="stylesheet" type="text/css" href="webjars/static/css/bootstrap.min.css"/> 
    <link rel="stylesheet" type="text/css" href="webjars/static/css/custom_test.css"/> 

또는

시도 HTML/Thymeleaf에서

src 
|--main 
    |--java 
    |--resources 
     |--public 
      |--css 
      |--bootstrap.min.css 
      |--custom_test.css 
      |--templates 
      |--.... 

이 중 지금까지 아무 것도 작동하지 않았습니다. 나는 같은 포블림으로 나와 다른 사람들을 도울 수 있기를 정말로 희망한다. 미리 감사드립니다.

+0

가능한 복제 [IntelliJ에 봄 부트 프로젝트가 Thymeleaf 내 CSS 파일을 찾을 수 없습니다]

@Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/").permitAll() .antMatchers("/favicon.ico").permitAll() .antMatchers("/css/**").permitAll() .antMatchers("/js/**").permitAll() .antMatchers("/static/**").permitAll() .antMatchers("/images/**").permitAll() .antMatchers("/blog/**").permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") .permitAll() .and() .logout() .permitAll(); } // ... } 
(http://stackoverflow.com/questions/40452365/intellij-spring-boot-project-cant-find-my-css-files-with-thymeleaf) – DimaSan

답변

0

문제점은 Spring Security의 구성 일 수 있습니다. 먼저 브라우저의 개발자 도구를 확인하고 클라이언트에서 얻지 못한 리소스에 대한 응답을 확인하십시오. 응답 상태 코드는 현재 구성에 따라 302 또는 401이 될 수 있습니다. 이런 경우

, 당신과 같은 프로젝트에 추가 구성을 추가해야 다음

+0

참으로 302 응답 코드였습니다. 도와 주셔서 대단히 감사합니다! – Marius

관련 문제