2015-12-23 4 views
1

У меня проблема с тем, что мои контроллеры Spring Spring отображаются другим способом, чем хотелось бы RestyGWT. Моя заявка на: http://localhost:8080/restgwt/RestyGWT- настраиваемый URL-адрес для службы весеннего отдыха

По 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> 

Моя весна служба/контроллер прослушивает: http://localhost:8080/restgwt/service/test

Но моя служба RestyGWT называет этот адрес: http://localhost:8080/restgwt/restgwt/test

И я не знаю, как рассказать RestyGWT об изменении url. Пожалуйста помоги.

Я знаю, что самое простое решение будет изменение в web.xml файла сервлета url-pattern параметра

от: <url-pattern>/service/*</url-pattern>

к: <url-pattern>/restgwt/*</url-pattern>

, но я хотел бы сделать RestyGWT, чтобы изменить его поведение.


Здесь вставить дополнительный код:

TestService на 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); 
} 

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(); 
    } 
} 

ответ

1

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()); 

Так что мой REST путь для RestyGWT становится http://domain-name/myGwtAppModuleName/rest/furtherPath где furtherPath это значение javax.ws.rs @Path (..) Ввод линии непосредственно в ГИНОМ 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()); 
    } 
    } 
+0

Я поместил это в класс '' ClientModule', и, к сожалению, я больше не могу скомпилировать gwt-проект. Я получаю сообщение об ошибке: '[INFO] Caused by: java.lang.UnsatisfiedLinkError: com.google.gwt.core.client.impl.Impl.getModuleBaseURL() Ljava/lang/String;' Можете ли вы помочь еще раз? – masterdany88

+0

np, у меня был тот же конец проблемы, который закончился, поставив этот кодовый блок в статику {Defaults.setServiceRoot (новый ресурс (GWT.getModuleBaseURL()). Resolve ("../ rest"). GetUri()); } блокировать внутри моего класса util на стороне клиента –

+0

Я поместил это в статический метод. Но все тот же. – masterdany88

 Смежные вопросы

  • Нет связанных вопросов^_^