将 GWT 与 Spring 集成

Kam*_*łys 5 java gwt spring maven

我知道这个话题已经被讨论过很多次了,但我发现大部分关于这个话题的信息都不是最新的。

我正在寻找有关如何将 GWT 与 Spring 框架集成的教程/示例。我发现了很多示例(其中一些甚至可以工作),但仅限于较旧的库。我正在寻找具有最新库(或至少与最新库兼容)的解决方案。

还有许多示例使用spring4gwt库(用于创建“粘合”servlet) - 还有其他方法吗?

我想使用创建简单的示例应用程序GWT + Spring + Hibernate + Maven。我从创建开始Web Application Project(从 Eclipse)。我将项目转换为 Maven 项目。老实说我被困在这里了。我可以创建简单的服务(+异步),但不知道如何配置正确的 servlet 并进一步。示例 我在 spring4gwt 上找到了relay,但我不想使用它(我认为自 2009 年以来就没有新版本了)。

如果有人可以逐步解释集成,那就太好了。

抱歉,如果这是重复的,但经过长时间的搜索,我没有找到适合我的需求的明确解决方案。

Ema*_*tto 0

我已经使用此设置创建了许多项目,您不需要 spring4gwt!我的解决方案是使用“桥”类,它允许您调用异步服务,例如 spring 控制器:

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.ServletContextAware;
import org.springframework.web.servlet.ModelAndView;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public abstract class BaseRemoteService extends RemoteServiceServlet implements
        ServletContextAware {

    private static final long serialVersionUID = 2470804603581328584L;
    protected Logger logger = Logger.getLogger(getClass());
    private ServletContext servletContext;

    @RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
    public ModelAndView handleRequest(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        doPost(request, response);
        return null; // response handled by GWT RPC over XmlHttpRequest
    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

    @Override
    public ServletContext getServletContext() {
        return this.servletContext;
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,您的 *RpcServiceImpl 应该类似于:

@Controller
@RequestMapping("/*/action.service")
public class ActionRpcServiceImpl extends BaseRemoteService implements ActionRpcService {
   //this class is managed by spring, so you can use @Autowired and other stuffs
   //implementation of your rpc service methods, 
}
Run Code Online (Sandbox Code Playgroud)