当前位置: 首页 > 工具软件 > Spring4GWT > 使用案例 >

gwt api_使用RequestFactory API进行Spring GWT集成

顾磊
2023-12-01

gwt api

从GWT 2.4开始,将RequestFactory API与后端的Spring服务集成很容易,您需要做的就是在服务器上创建一个自定义ServiceLocator,GWT将使用它来正确定位被调用的服务:

public class SpringServiceLocator implements ServiceLocator {

 public Object getInstance(Class clazz) {
  ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(
    RequestFactoryServlet.getThreadLocalServletContext());
  return context.getBean(clazz);
 }
}

第二步是像这样在web.xml上声明您的RequestFactory servlet,(我假设您已经进行了弹簧设置):

<servlet>

 <servlet-name>requestFactoryServlet</servlet-name>

 <servlet-class>org.gxpenses.util.SpringRequestServlet</servlet-class>

 <load-on-startup>1</load-on-startup>

</servlet>



<servlet-mapping>

 <servlet-name>requestFactoryServlet</servlet-name>

 <url-pattern>/gwtRequest</url-pattern>

</servlet-mapping>

和GWT一样,您必须配置代理(因为使用服务样式后端,因此必须使用ValueProxy而不是EntityProxy)和作为服务远程接口的请求:

//Note that I inherit from the ValueProxy object

@ProxyFor(Account.class)

public interface AccountProxy extends ValueProxy {

 public String getId();

 public void setId(String id);

 public String getName();

 public void setName(String name);

 public Double getBalance();

 public void setBalance(Double balance);

 public String getType();

 public void setType(String type);

}



//You have to provide you service Impl class, and the ServiceLocator you created

//Note that Account is automatically to AccountProxy on the client

@Service(value=AccountsServiceImpl.class, locator=SpringServiceLocator.class)

public interface AccountRequest extends RequestContext {

 abstract Request<Void> createNewAccount(AccountProxy account);

 abstract Request<Void> updateAccountBalance(String accountId, Double transactionAmount, String type);

 abstract Request<Double> totalAmountByAccountAndPeriodeAndType(String accountId, Date start, Date end, String type);

}

集成就是这样,有关如何使用RequestFactory API的更多信息,请参见: RequestFactory API

参考: Fancy UI博客中的JCG合作伙伴 Idriss Mrabti 使用RequestFactory API进行的Spring GWT集成

相关文章 :


翻译自: https://www.javacodegeeks.com/2011/12/spring-gwt-integration-using.html

gwt api

 类似资料: