使用STS或者eclipse 開發SpringMVC應用 時,我靠。。有個小小的東西沒注意搞了半天,
STS在創建SpringMVC工程時,自動生成了Dispatcher的配置文件,然后看教程時,使用了<mvc:annotation-driven> 注解配置
但是自動生成的xml里呢有一個<annotation-driven>, 挺疑惑的,以為mvc約束文件版本不對,所以配置了很久的本地約束,仍然沒有用
后來決定仔細看看什么問題,通過代碼排版對齊,發現了。。。。。靠,前綴也是需要配置的!!改成下面所示代碼。OK了
注意藍色的是以前的,改成紅色的,就多了個 :mvc
The prefix "mvc" for element "mvc:annotation-driven" is not bound異常
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns= "http://www.springframework.org/schema/mvc"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
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">
<mvc:annotation-driven />
<mvc:resources location="/resources/" mapping="/resources/**"/>
</beans:beans>