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>
相关推荐
吃海鲜的骆驼几秒前
服务异步通讯与RabbitMQ
java·分布式·后端·rabbitmq
m0_748233642 分钟前
RabbitMQ 进阶
android·前端·后端
羱滒4 分钟前
sql调优之数据库开发规范
java·数据库·数据库开发
m0_7482386311 分钟前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
Forget the Dream33 分钟前
设计模式之责任链模式
java·c++·设计模式·责任链模式
jonyleek36 分钟前
「JVS更新日志」低代码、企业会议、智能BI、智能排产2.26更新说明
java·大数据·低代码·数据分析·软件需求
计算机小白一个1 小时前
蓝桥杯 Java B 组之最短路径算法(Dijkstra、Floyd-Warshall)
java·数据结构·算法·蓝桥杯
曼岛_1 小时前
[密码学实战]Java实现SM4加解密(ecb,cbc)及工具验证
java·密码学
菜鸟阿达1 小时前
spring boot 2.7 + seata +微服务 降级失败问题修复
spring boot·后端·微服务
清河__1 小时前
【Go】十七、grpc 服务的具体功能编写
开发语言·后端·golang