2017-03-26 1 views
0

문제는 일반적이며 많은 해결책을 시도했지만 나에게 맞는 것은 없습니다. 나는 봄에 아주 새로운데, 그래서 나는 어떤 것을 이해하지 못할 수도있다.Java Spring-MVC 애플리케이션이 CSS 및 JS 파일을 보내지 않습니다. 오류 404

나는 다음 파일 구조를 가지고 : 페이지 내부

Files structure of project

내 링크가이 같은 Thymeleaf에 의해 템플릿된다

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

또한, HTML의 머리에 속성이있다.

좋아, 내 스프링의 context.xml은 다음과 같습니다

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 
    <!--to pick up all annotation in the package--> 
    <context:component-scan base-package="langquiz"/> 

    <mvc:annotation-driven /> 
    <mvc:resources mapping="/css/**" location="/css/"/> 
</beans> 

나는 ("/ 템플릿/CSS /"또는 위치 = "CSS /"= 위치를 쓰는 같은) 매핑에 몇 가지 조작을 시도했습니다 또한 구성 클래스에서 자원 처리기를 시도했습니다. 그러나 아무것도 도움이되지 않습니다.

감사합니다.

는 UPD :

<mvc:resources mapping="/css/**" location="/templates/"/> 

<mvc:resources mapping="/css/**" location="/css/"/> 

을 변경하고 또한

<mvc:resources mapping="/css/**" location="/"/> 

을 시도했지만 여전히 결과가 없습니다.

+0

에 웹 사이트를 볼 수있는 방법이 있는지

아직도 궁금해? – chrylis

+0

@chrylis 예, Spring-MVC + ThymeLeaf입니다. – utkillr

답변

1

사용

<mvc:resources mapping="/css/**" location="/templates/css/"/> 

또는 자원 핸들러를 추가

@Configuration 
public class WebConfig extends WebMvcConfigurerAdapter { 

@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) { 
    registry.addResourceHandler("/css/**").addResourceLocations("/templates/css/"); 
} 

가}

1
아래 그림과 같이 location뿐만 아니라 당신의 templates 디렉토리를 포함해야하는 당신의 매핑이 잘못

이에 봄 문서에서

<mvc:resources mapping="/css/**" location="/templates/css/"/> 

당신은 참조 할 수 here : 예를 들어

에 URL 패턴이 /resources/이고 공용 리소스 디렉토리에서 리소스 요청을 제공합니다. 웹 응용 프로그램 루트 ithin 다음을 사용 :

<mvc:resources mapping="/resources/**" location="/public-resources/"/> 
+0

변경 했는데도 작동하지 않습니다. – utkillr

+0

그 밖의 무엇이 누락 될 수 있습니까? – utkillr

+0

리소스를 취하려고하는 위치를 확인할 수 있습니까? – utkillr

관련 문제