在我的春天应用程序,我下面从这篇文章的提示:
http://www.java-allandsundry.com/2012/10/spring-mvc-static-resource-handling.html
映射到我的资源文件(CSS,JS等)。
问题是,当我把我的弹簧servlet.xml文件的代码,当我尝试运行应用程序(甚至无显示页)我收到一个404错误:
<mvc:resources mapping="/bootstrap/**" location="/bootstrap/" />
<mvc:resources mapping="/extras/**" location="/extras/" />
<mvc:resources mapping="/jquery/**" location="/jquery/" />
这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>HorarioLivre2</display-name>
<welcome-file-list>
<welcome-file>acesso/login.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>HorarioLivre2</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HorarioLivre2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
只是为了记录在案,如果我从我的* -servlet.xml后缀文件中删除上面的3行,我只可以访问我的应用程序,如果我替换此行:
<url-pattern>/</url-pattern>
由一个:
<url-pattern>*.html</url-pattern>
有人知道如何与MVC正确配置资源映射:资源?
我* -servlet.xml后缀
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
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
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<context:component-scan base-package="com.horariolivre"/>
<mvc:annotation-driven></mvc:annotation-driven>
<mvc:resources location="/bootstrap/" mapping="/bootstrap/**" />
<mvc:resources location="/extras/" mapping="/extras/**" />
<mvc:resources location="/jquery/" mapping="/jquery/**" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<context:annotation-config>
<bean class="com.horariolivre.resources.HibernateConfig">
</bean>
</context:annotation-config>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
如何我包括资源,我的JSP文件:
<!-- Bootstrap core CSS -->
<link href="<c:out value="/bootstrap/css/bootstrap.min.css"/>" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="<c:out value="/extras/css/signin.css"/>" rel="stylesheet">