RestyGWT- 为 spring 休息服务定制 url 映射
RestyGWT- custom url mapping for spring rest service
我的 Spring Rest Controllers 的映射方式与 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 service/controller 听着:
http://localhost:8080/restgwt/service/test
但是我的 RestyGWT 服务调用这个 url:
http://localhost:8080/restgwt/restgwt/test
而且我不知道如何告诉 RestyGWT 进行更改 url
。请帮忙。
我知道最简单的解决方案是更改 web.xml
文件 servlet url-pattern
参数
来自:<url-pattern>/service/*</url-pattern>
至:<url-pattern>/restgwt/*</url-pattern>
但我想让 RestyGWT 改变它的行为。
这里粘贴一些额外的代码:
GWT 端的测试服务
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 端的测试服务
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();
}
}
Reffering to the official documentation:
Configuring service root URLs
There are two ways to configure service root URLs which are appended with the @Path annotation property when building the final service URL. For single service root URL the Defaults.setServiceRoot(String) method can be used. When several services with different service roots are used the @Options annotation is equipped with the serviceRootKey property which can be set to read service root entries provided with the static ServiceRoots.add(String, String) method.
Defaults.setServiceRoot(new Resource( GWT.getModuleBaseURL()).resolve("../rest").getUri());
所以我的 RestyGWT REST 路径变成 http://domain-name/myGwtAppModuleName/rest/furtherPath
其中 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());
}
}
我的 Spring Rest Controllers 的映射方式与 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 service/controller 听着:
http://localhost:8080/restgwt/service/test
但是我的 RestyGWT 服务调用这个 url:
http://localhost:8080/restgwt/restgwt/test
而且我不知道如何告诉 RestyGWT 进行更改 url
。请帮忙。
我知道最简单的解决方案是更改 web.xml
文件 servlet url-pattern
参数
来自:<url-pattern>/service/*</url-pattern>
至:<url-pattern>/restgwt/*</url-pattern>
但我想让 RestyGWT 改变它的行为。
这里粘贴一些额外的代码:
GWT 端的测试服务
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 端的测试服务
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();
}
}
Reffering to the official documentation:
Configuring service root URLs There are two ways to configure service root URLs which are appended with the @Path annotation property when building the final service URL. For single service root URL the Defaults.setServiceRoot(String) method can be used. When several services with different service roots are used the @Options annotation is equipped with the serviceRootKey property which can be set to read service root entries provided with the static ServiceRoots.add(String, String) method.
Defaults.setServiceRoot(new Resource( GWT.getModuleBaseURL()).resolve("../rest").getUri());
所以我的 RestyGWT REST 路径变成 http://domain-name/myGwtAppModuleName/rest/furtherPath
其中 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());
}
}