GWT2与Spring的Exporter方式集成。
--- web.xml
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>gwt</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>gwt</servlet-name>
<url-pattern>/gwt/*</url-pattern>
</servlet-mapping>
-- gwt-servlet.xml(spring)
<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<map>
<entry key="com.extjs.gxt.samples.test.ImageViewer/HelloWordService"
value-ref="hellowordService" />
</map>
</property>
</bean>
<bean id="RPCExporter" abstract="true" class="org.gwtwidgets.server.spring.GWTRPCServiceExporter"/>
<bean id="hellowordServiceImpl" class="com.extjs.gxt.samples.test.server.HelloWordServiceImpl" />
<bean id="hellowordService" parent="RPCExporter">
<property name="service" ref="hellowordServiceImpl" />
</bean>
-- HelloWordService(gxt client)
@RemoteServiceRelativePath("HelloWordService")
public interface HelloWordService extends RemoteService {
String sayHello(String name);
/**
* Utility class for simplifying access to the instance of async service.
*/
public static class Util {
private static HelloWordServiceAsync instance;
public static HelloWordServiceAsync getInstance(){
if (instance == null) {
instance = GWT.create(HelloWordService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) instance;
endpoint.setServiceEntryPoint("http://127.0.0.1:8888/gwt/com.extjs.gxt.samples.test.ImageViewer/HelloWordService");
}
return instance;
}
}
}
-- HelloWordServiceAsync(gxt client)
public interface HelloWordServiceAsync {
void sayHello(String name, AsyncCallback<String> callback);
}
-- HelloWordServiceImpl(gxt server)
public class HelloWordServiceImpl extends RemoteServiceServlet implements HelloWordService {
public HelloWordServiceImpl() {
super();
// TODO Auto-generated constructor stub
}
public HelloWordServiceImpl(Object delegate) {
super(delegate);
// TODO Auto-generated constructor stub
}
@Override
public String sayHello(String name) {
// TODO Auto-generated method stub
return "hello "+name;
}
}
如果有用开发工具生成的gwt server要注意它的entrypoint在客户端的路径