将DWR添加到SpringMVC,但没有效果。当我访问一个Controller时,在控制台中抛出一个错误。
LOG: org.springframework.web.servlet.PageNotFound noHandlerFound 警告:在DispatcherServlet中找不到带有URI [/ YouthDesign / reverseAjax / toPeopleTable]的HTTP请求的映射,名称为“springmvc”
的web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Touth Design</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/application-cfg.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/springmvc-cfg.xml,
classpath*:/dwr-cfg.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- <servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>activeReverseAjaxEnabled</param-name>
<param-value>true</param-value>
</init-param>
</servlet> -->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
springmvc-cfg.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.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-4.3.xsd">
<context:component-scan base-package="com.youthdesign.web">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<mvc:annotation-driven />
<!-- 映射静态资源 -->
<mvc:resources location="/static/" mapping="/resources/**"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp"/>
</bean>
</beans>
DWR-cfg.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:context="http://www.springframework.org/schema/context"
xmlns:spring-dwr="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation="http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr/spring-dwr-3.0.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-4.3.xsd">
<spring-dwr:configuration />
<spring-dwr:url-mapping />
<spring-dwr:controller id="dwrController" debug="true">
<spring-dwr:config-param name="activeReverseAjaxEnabled" value="true"/>
</spring-dwr:controller>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true"/>
<property name="mappings">
<props>
<prop key="/dwr/**/*">dwrController</prop>
</props>
</property>
</bean>
<spring-dwr:annotation-scan base-package="com.youthdesign" scanDataTransferObject="true" scanRemoteProxy="true"/>
</beans>
以上是我的配置文件,请帮助,谢谢大家。
答案 0 :(得分:0)
我已经解决了这个问题。如果你正在学习dwr并希望将它与spring一起使用。你可以参考我在Github上的演示。 https://github.com/BigRui/simpleDWR