【问题标题】:RestyGWT- custom url mapping for spring rest serviceRestyGWT - spring rest服务的自定义url映射
【发布时间】:2016-03-29 14:56:15
【问题描述】:

我的 Spring Rest 控制器以其他方式映射而不是 RestyGWT 的问题。 我的申请开启:http://localhost:8080/restgwt/

根据web.xml:

<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/action-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/service/*</url-pattern>
</servlet-mapping>

我的 Spring 服务/控制器监听: http://localhost:8080/restgwt/service/test

但是我的 RestyGWT 服务调用了这个 url: http://localhost:8080/restgwt/restgwt/test

而且我不知道如何告诉 RestyGWT 更改 url。请帮忙。

我知道最简单的解决方案是更改 web.xml 文件 servlet url-pattern 参数

来自:&lt;url-pattern&gt;/service/*&lt;/url-pattern&gt;

收件人:&lt;url-pattern&gt;/restgwt/*&lt;/url-pattern&gt;

但我想让 RestyGWT 改变它的行为。


这里粘贴一些额外的代码:

GWT 端的TestService

package pl.korbeldaniel.restgwt.client;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import org.fusesource.restygwt.client.MethodCallback;
import org.fusesource.restygwt.client.RestService;

public interface TestService extends RestService {
    @GET
    @Path("test")
    public void getInfo(MethodCallback<TestPojo> test);
}

Spring 端的TestService

package pl.korbeldaniel.restgwt.server;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController()
public class TestService {
    @RequestMapping(value = "test", method = RequestMethod.GET)
    public @ResponseBody TestEntity getInfo() {
        TestEntity test = new TestEntity();
        System.out.println("Hit server for getting _1");
        return new TestEntity();
    }
}

【问题讨论】:

    标签: spring rest spring-mvc gwt resty-gwt


    【解决方案1】:

    Reffering to the official documentation:

    配置服务根 URL 在构建最终服务 URL 时,有两种方法可以配置附加 @Path 注释属性的服务根 URL。对于单个服务根 URL,可以使用 Defaults.setServiceRoot(String) 方法。当使用具有不同服务根的多个服务时,@Options 注释配备了 serviceRootKey 属性,该属性可以设置为读取静态 ServiceRoots.add(String, String) 方法提供的服务根条目。

    Defaults.setServiceRoot(new Resource( GWT.getModuleBaseURL()).resolve("../rest").getUri());
    

    所以我的 RestyGWT REST 路径变成了http://domain-name/myGwtAppModuleName/rest/furtherPath 其中进一步路径是 javax.ws.rs @Path(..) 值 将线路直接放入 GIN ClientModule 失败,java.lang.UnsatisfiedLinkError: com.google.gwt.core.client.impl.Impl.getModuleBaseURL()Ljava/lang/String 为了避免错误,我已经把它包起来了

        public class ClientModule extends AbstractPresenterModule {
            @Override
            protected void configure(){
               //your installs and binds here
               bind(RestyGwtConfig.class).asEagerSingleton();
            }
        }
    
        public class RestyGwtConfig {
        static {
        Defaults
    .setServiceRoot(new Resource( GWT.getModuleBaseURL()).resolve("../rest").getUri());
        }
        }
    

    【讨论】:

    • 我已经把它放在ClientModule 类中,不幸的是我不能再编译gwt 项目了。我收到一个错误:[INFO] Caused by: java.lang.UnsatisfiedLinkError: com.google.gwt.core.client.impl.Impl.getModuleBaseURL()Ljava/lang/String; 你能再帮忙吗?
    • np,我遇到了同样的问题,最后只是将此代码块放在静态 { Defaults.setServiceRoot(new Resource( GWT.getModuleBaseURL()).resolve("../rest") .getUri()); } 在客户端的 util 类中阻塞
    • 我把它放在了静态方法中。但还是一样。
    • 您使用的是 .client。包作为您服务器上的导入?我的是 org.fusesource.restygwt.client.Defaults;和 org.fusesource.restygwt.client.Resource;
    • 没有。我想我没有。
    猜你喜欢
    • 2010-11-23
    • 1970-01-01
    • 2016-01-04
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多