SpringMVC 萬用字元的匹配很全面, 但無法找到元素 'mvc:default-servlet-handler' 的宣告。
阿新 • • 發佈:2019-01-30
問題描述:萬用字元的匹配很全面, 但無法找到元素 'mvc:default-servlet-handler' 的宣告。
原因:
雖然在xml檔案上方聲明瞭mvc,但沒有配置此宣告對應的檔案資訊,正確配置如下:
mvc宣告用http://www.springframework.org/schema/mvc/spring-mvc.xsd這個檔案來解析,一個宣告必須跟著一組類似網址的檔案來解析。
<?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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 掃描web包,應用Spring的註解 --> <context:component-scan base-package="com.htk.web"/> <!-- 靜態資源(js、image等)的訪問 --> <mvc:default-servlet-handler/> <!-- 開啟註解 --> <mvc:annotation-driven/>