바람둥이 mvc 3 함께 일하고 있습니다. 정적 리소스로드 문제가 발생했습니다. 다음과 같이봄 mvc 정적 리소스 구성 문제
내 디렉토리 구조는 다음과 같습니다 나는 이미 정적이 내가 설정 한 요청 매핑에 잡힐되지 않았 음을 확인했다있다
-static
-common
- paths to static
- WEB-INF
. 내가 그들을 검색 갈 때마다 다음과 같이하지만, 난 그냥 404를 얻을 :
여기GET http://localhost:8080/YouthMinistryHibernate/static/common/css/compiled.css 404 (Not Found)
GET http://localhost:8080/YouthMinistryHibernate/static/common/js/compiled.js 404 (Not Found)
내 web.xml에 있습니다 :
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>YouthMinistryHibernate</display-name>
<!-- Spring MVC -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring/root-context.xml</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>simple</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>deepDishCMSServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<init-param>
<param-name>spring.profiles.default</param-name>
<param-value>simple</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>deepDishCMSServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>hiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
내 스프링 MVC 설정 파일 :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<mvc:resources mapping="/static/**" location="/static/" />
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="message" />
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
<property name="order">
<value>1</value>
</property>
</bean>
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>image/jpeg</value>
<value>image/png</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
</beans>
두 가지 방법을 사용하여 리소스를 가져 오려고했습니다 :
<link rel="stylesheet" type="text/css" href="${ pageContext.request.contextPath }/static/common/css/compiled.css" />
하고 여기에
<script type="text/javascript" src="<c:url value="/static/common/js/compiled.js" />"></script>
는 경우뿐만 아니라 GitHub의에서 프로젝트에 대한 링크입니다 :
http://github.com/dmcquillan314/YouthMinistryHibernate
어떤 도움을 크게 감사합니다. 나는이 리소스에 액세스하려고 할 때
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${project.basedir}/src/main/resources/build.sh</executable>
<arguments>
<argument>${env}</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
</execution>
</executions>
<configuration>
<warSourceExcludes>static/common/js/**</warSourceExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<warName>YouthMinistryHibernate</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url></url>
<server>TomcatServer</server>
<path>/YouthMinistryHibernate</path>
</configuration>
<version>1.1</version>
</plugin>
디버그 로그 : 아래
내 pom.xml 파일의 관련 구성입니다DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/static/common/js/compiled.js]
DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/static/common/js/compiled.js] are [/static/**]
DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/static/common/js/compiled.js] are {}
DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/static/common/js/compiled.js] to HandlerExecutionChain with handler [org.[email protected]569939c1] and 1 interceptor
DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/YouthMinistryHibernate/static/common/js/compiled.js] is: -1
DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Trying relative path [common/js/compiled.js] against base location: ServletContext resource [/static/]
DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - No matching resource found - returning 404
DEBUG: org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'deepDishCMSServlet': assuming HandlerAdapter completed request handling
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
UPDATE를
아직 고정하지 않은 그러나이 문제는 모든 코드베이스를 살펴보고 지금까지 아무 도움이되지 않은 것을 발견했습니다. 지금은 내 코드가 어디서 붙어 있는지 보려고 주변을 둘러보고 있습니다.
mvc : resource를 정적 파일 요청 매핑에서로드 할 때 사용하지 않는 것처럼 문제가 spring mvc config 어딘가에있을 수 있습니다. 내 MVC 구성은 다음과 같습니다.
<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:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!-- Configure the multipart resolver -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="100000"/>
</bean>
<mvc:resources mapping="/static/**" location="/static/" />
<!-- Add controller package to be scanned for this path -->
<context:component-scan base-package="com.youthministry.controller"/>
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
<property name="order">
<value>1</value>
</property>
</bean>
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>image/jpeg</value>
<value>image/png</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
</beans>
응용 프로그램에 대해'context.xml'을 설정 했습니까? pom 내부에 최종 이름을 설정 했습니까? 그렇지 않다면 컨텍스트 이름은'YouthMinistryHibernate - $ {pom.version} '입니다. –
pom.xml의 관련 정보로 게시물을 업데이트했습니다. – dmcqu314
정적 URL에 액세스하려고하면 로그에 무엇이 있습니까? 'logger.org.springframework.web.servlet' logger를'DEBUG'로 설정하고 출력을 붙여 넣으십시오. – soulcheck