springboot整合dwr

1、引入pom

org.directwebremoting

dwr

3.0.2-RELEASE

2、dwr.xml东西移动到java

后台服务(@RemoteProxy @RemoteMethod)

bash 复制代码
public interface DemoServiceI {
    public String hello();

    public String echo(String string) ;
}
@Service("DemoService")
@RemoteProxy(name = "DemoService")
public class DemoServiceImpl implements DemoServiceI{
    // 这里也可以使用 @Autowired 注入依赖的其他服务

    @RemoteMethod
    public String hello() {
        return "hello";
    }

    @RemoteMethod
    public String echo(String string) {
        return string;
    }
}
3、配置DwrSpringServlet 

```bash
@Configuration
public class DwrConfig {
    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        DwrSpringServlet servlet = new DwrSpringServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet, "/dwr/*");
        registrationBean.addInitParameter("debug", "true");
        return registrationBean;
    }



}
复制代码
4、xml扫描

```bash
<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
 
    <dwr:annotation-config/>
 
    <dwr:annotation-scan scanRemoteProxy="false" base-package="com.aa.dwr"/>
 
    <dwr:configuration/>
</beans>
	<!-- 如果有类型转换的 -->
	<dwr:configuration>
		<dwr:convert type="bean" class="com.UnionOrderType">
	 </dwr:convert>
	</dwr:configuration>

4、js中引入

bash 复制代码
<html>
<head>
    <title></title>
    <script type='text/javascript' src='/dwr/engine.js'></script>
    <script type='text/javascript' src='/dwr/interface/DemoService.js'></script>
</head>
hello
<script>
    DemoService.echo('测试', function (str) {
        alert(str);
    });
</script>
</html>
相关推荐
旷野说1 分钟前
为什么 MyBatis 原生二级缓存“难以修复”?
java·java-ee·mybatis
8***23554 分钟前
【wiki知识库】07.用户管理后端SpringBoot部分
java
bcbnb5 分钟前
iOS 性能测试的工程化方法,构建从底层诊断到真机监控的多工具测试体系
后端
开心就好20258 分钟前
iOS 上架 TestFlight 的真实流程复盘 从构建、上传到审核的团队协作方式
后端
小周在成长16 分钟前
Java 泛型支持的类型
后端
aiopencode17 分钟前
Charles 抓不到包怎么办?HTTPS 抓包失败、TCP 数据流异常与底层补抓方案全解析
后端
阿蔹20 分钟前
JavaWeb-Selenium 配置以及Selenim classnotfound问题解决
java·软件测试·python·selenium·测试工具·自动化
稚辉君.MCA_P8_Java22 分钟前
Gemini永久会员 C++返回最长有效子串长度
开发语言·数据结构·c++·后端·算法
Penge66640 分钟前
Redis-bgsave浅析
redis·后端
阿白的白日梦1 小时前
Windows下c/c++编译器MinGW-w64下载和安装
c语言·后端