You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring MVC 3.0整合DWR 3.0.2的SchemaLocation命名空间错误问题

一、DWR 3.0.2与Spring Web MVC 3.0整合错误修复

1. 先修正XML语法低级错误

你的servlet.xml里<beansxmlns少了空格,这直接导致命名空间无法被识别,改成:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

2. 解决XSD引用错误

提示的XSD文件问题,是因为远程地址映射不到jar包内的本地文件。先确保项目里已经引入dwr-spring-3.0.2.jar,然后把schemaLocation改成类路径引用,Spring会自动从jar包加载:

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.directwebremoting.org/schema/spring-dwr classpath:org/directwebremoting/spring/spring-dwr-3.0.xsd"

3. 替换自定义Controller为官方实现

你现在用的com.Controller.java.DwrController是自定义类,DWR和Spring整合必须用官方提供的org.directwebremoting.spring.DwrController,改成:

<!-- 删除自定义的dwrController,替换成官方实现 -->
<bean id="dwrController" class="org.directwebremoting.spring.DwrController">
    <property name="debug" value="true"/>
</bean>

之前注释的<dwr:controller>标签不用管,和这个bean配置二选一即可,用bean配置更直观。

4. 修正dwr:remote配置

dwr:remote的service属性必须指向Spring容器里已存在的bean的id,比如先定义服务bean,再配置远程暴露:

<!-- 先定义要暴露的远程服务bean -->
<bean id="MyRemoteObject" class="com.yourpackage.MyRemoteObject"/>

<!-- 配置DWR暴露该服务 -->
<dwr:remote name="myRemoteMethod" service="MyRemoteObject">
    <!-- 可选:指定要暴露的方法,默认暴露所有公共方法 -->
    <dwr:include method="yourTargetMethod"/>
</dwr:remote>

5. 检查依赖完整性

确保项目依赖包含这些jar包:

  • dwr-3.0.2.jar
  • dwr-spring-3.0.2.jar
  • Spring Web MVC 3.0.x相关jar(spring-web、spring-webmvc等)
二、Spring 3.0的DWR替代方案

针对非Spring Boot的Spring 3.0项目,推荐这几个开源方案:

  • Spring MVC原生AJAX支持:用@ResponseBody注解直接返回JSON/XML,前端用原生AJAX或jQuery调用,不用额外框架,简单场景够用。
  • Apache Wicket:支持组件化AJAX,和Spring整合顺畅,适合复杂UI交互的项目,但需要花点时间学习。
  • GWT(Google Web Toolkit):能把Java代码编译成JavaScript,实现前后端同构,适合大型富客户端应用,但构建流程稍复杂。
  • JSON-RPC Java:轻量级JSON-RPC实现,和Spring MVC整合简单,专注于远程方法调用场景。

内容的提问来源于stack exchange,提问作者Specter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 03:41:21