看一下实现一个非常基本的java spring应用程序。目前我正在尝试在视图中包含js / css文件。当我在schemaLocation下的mvc-dispatcher-servlet.xml文件中添加必要的信息时,我的网站会抛出404错误。
MVC-调度-servlet.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
--breaks things http://www.springframework.org/schema/mvc
--breaks things http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.pkg"/>
<mvc:resources mapping="/resources/**" location="/resources/css/" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
pom.xml依赖调用
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
视图
<link href="<c:url value="/resources/css/file.css" />" rel="stylesheet">