spring集成gwt的办法

spring集成gwt的办法

spring集成gwt,没有官方的解决方案,无论spring还是gwt。

在这里使用了第三方的一个集成方法,见:

http://code.google.com/p/spring4gwt/

使用的步骤为,首先,需要将该项目的jar文件放置到WEB-INF/lib目录下。

 

然后,需要在web.xml文件中设置对spring的支持:

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener>

<servlet> 
    <servlet-name>springGwtRemoteServiceServlet</servlet-name> 
    <servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class> 
</servlet> 
<servlet-mapping> 
    <servlet-name>springGwtRemoteServiceServlet</servlet-name> 
    <url-pattern>/standard_console/rpc/*</url-pattern> 
</servlet-mapping>

 

其中,listener部分,是加载spring的webapplication context的,SpringGwtRemoteServiceServlet部分,是spring4gwt实现的集成spring和gwt的解决方案。gwt原本是要求写Servlet作为rpc的实现的,然后一个一个的配置到web.xml文件中。有了这个解决方案,具体的rpc的servlet就被spring的bean替代了,这里的*通配所有bean的名字,springGwtRemoteServiceServlet会根据spring的Context获取到具体的实现bean。

那么需要在WEB-INF目录下有一个名为applicationContext.xml的文件,比如:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx"xmlns:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd 
http://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-2.5.xsd 
http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsd 
http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd"
     <context:component-scan base-package="com.easymorse.server" /> 
</beans>

这里设置扫描的package就是你服务器端gwt rpc的包名。

做rpc的类:

package com.easymorse.server;

import org.springframework.stereotype.Service;

import com.easymorse.client.GreetingService; 
import com.easymorse.client.bean.BlackUser;

@Service("greet") 
public class GreetingServiceImpl implements 
        GreetingService {

    @Override 
    public String greetServer(BlackUser blackUser) { 
        return "中文"; 
    } 
}

 

另外,别忘记在gwt client端的代码中做路径的设置:

package com.easymorse.client;

import com.easymorse.client.bean.BlackUser; 
import com.google.gwt.user.client.rpc.RemoteService; 
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

/** 
* The client side stub for the RPC service. 
*/ 
@RemoteServiceRelativePath("rpc/greet") 
public interface GreetingService extends RemoteService { 
    String greetServer(BlackUser blackUser); 
}

 

这里的路径是rpc/greet,其中greet就是bean的名字。

这样,就可以在不影响gwt的各种配置的情况下,实现了简单的基于spring的rpc。

功能: 实现数据分页查询显示 特点: 全是免费工具及开源技术 开发框架: gwt1.4.6 + spring2.5 + mysql5.0 开发工具: Eclipse3.4 Cypal Studio for GWT (Eclipse 的一个插件) 实现原理:通过GWT的RPC来调用Spring 传过来的服务器端数据 注意:需要的jar包 * gwt-user.jar * gwt-servlet.jar * mysql-connectot-java-3.1.12.jar * spring.jar * commons-dbcp.1.2.1.jar * coommons-pool-1.4.jar Sql语句: create database booksearch; create table book ( id int not null auto_increment primary key, title varchar(100), isbn varchar(100), edition varchar(100), msrp varchar(100) ) insert into book(title,isbn,edition,msrp) values('title_1','i-sbn-1','editon-1','msrp-1'); insert into book(title,isbn,edition,msrp) values('title_2','i-sbn-2','editon-2','msrp-2'); insert into book(title,isbn,edition,msrp) values('title_3','i-sbn-3','editon-3','msrp-3'); insert into book(title,isbn,edition,msrp) values('title_4','i-sbn-4','editon-4','msrp-4'); insert into book(title,isbn,edition,msrp) values('title_5','i-sbn-5','editon-5','msrp-5'); insert into book(title,isbn,edition,msrp) values('title_6','i-sbn-6','editon-6','msrp-6'); insert into book(title,isbn,edition,msrp) values('title_7','i-sbn-7','editon-7','msrp-7'); insert into book(title,isbn,edition,msrp) values('title_8','i-sbn-8','editon-8','msrp-8'); insert into book(title,isbn,edition,msrp) values('title_9','i-sbn-9','editon-9','msrp-9'); insert into book(title,isbn,edition,msrp) values('title_10','i-sbn-10','editon-10','msrp-10');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值