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>
相关推荐
装不满的克莱因瓶2 分钟前
Java7新特性:try-with-resources写法
java·前端·javascript·jdk·新特性·jdk7
前路不黑暗@18 分钟前
Java项目:Java脚手架项目的通用组件的封装(六)
java·开发语言·spring
马士兵教育32 分钟前
程序员简历如何编写才能凸显出差异化,才能拿到更多面试机会?
开发语言·后端·面试·职场和发展·架构
chilavert3181 小时前
技术演进中的开发沉思-368:锁机制(中)
java·开发语言·jvm
~央千澈~2 小时前
抖音弹幕游戏开发之第12集:添加冷却时间机制·优雅草云桧·卓伊凡
java·服务器·前端
HAPPY酷2 小时前
C++ 多线程实战三板斧
java·开发语言·c++·技术美术
独自破碎E2 小时前
BISHI54货物堆放
android·java·开发语言
json{shen:"jing"}2 小时前
分割回文串
java
workflower2 小时前
易用性和人性化需求
java·python·测试用例·需求分析·big data·软件需求
无心水2 小时前
5、微服务快速启航:基于Pig与BladeX构建高可用分布式系统实战
服务器·分布式·后端·spring·微服务·云原生·架构