2013-03-20 127 views
1

在我的上下文文件中,我想添加一行以便能夠訪問靜態內容。直到我添加它,一切正常,但添加後,我不能訪問有一些控制器的頁面,我得到這個警告:WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/fit/] in DispatcherServlet with name 'mvc-dispatcher'。加入<mvc:resources mapping="/resources/**" location="/resources/" />上下文文件之前,它看起來像這樣:執行資源映射後,Spring MVC映射不起作用

<?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:context="http://www.springframework.org/schema/context" 
xmlns:security="http://www.springframework.org/schema/security" 
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.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> 

<context:annotation-config /> 

<!-- Handles HTTP GET requests for /resources/** by efficiently serving 
    up static resources in the ${webappRoot}/resources directory --> 




<context:component-scan base-package="cz.cvut.fit.genepi.controllers" /> 
<import resource="classpath:applicationContext-security.xml" /> 
<bean 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/views/" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 

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

任何想法如何解決這一問題? PS:這些頁面用Spring安全保護,但我不認爲這可能是問題。

+0

請張貼您的Web.xml和一個Jsp和控制器also.I wana檢查您如何映射傳入的請求以及如何使用您的JSP頁面中的靜態內容。 – beinghuman 2013-09-09 12:20:02

+0

哦..這個話題在這一刻並不是真的,問題解決了。我會用代碼發佈答案。感謝提醒:] – Dworza 2013-09-09 14:45:57

+0

解決方案是什麼?我沒有找到你說的答案:( – 2016-06-09 18:46:52

回答

1

每個調度程序servlet都以-servlet結尾。 嘗試重命名您的調度程序servlet。

在初始化DispatcherServlet時,框架將在您的Web應用程序的WEB-INF目錄中查找名爲[servlet-name] -servlet.xml的文件,並創建在那裏定義的bean。

+0

這不會是問題,我在'web.xml'中明確定義了調度程序servlet的路徑' \t \t mvc-dispatcher \t \t org.springframework.web.servlet.DispatcherServlet \t \t \t \t \t​​contextConfigLocation的 \t \t \t /WEB-INF /的applicationContext.xml \t \t \t \t <時加載的啓動> 1 \t'...正如我說過的 - 一切正常,直到我添加一行' ' – Dworza 2013-03-21 09:06:35