我成功地遵循GWT和spring4gwt的教程,并通过以下配置将StockWatcher的演示转换为启用Spring(3.0)的服务:
web.xml:
<servlet-mapping>
<servlet-name>springGwtRemoteServiceServlet</servlet-name>
<!-- stockWatcher module is rename-to="stock" -->
<url-pattern>/stock/spring/*</url-pattern>
</servlet-mapping>
StockPriceService.java:
@RemoteServiceRelativePath("spring/stockPriceService")
public interface StockPriceService extends RemoteService
{
StockPrice[] getPrices(String[] symbols) throws DelistedException;
}
spring的app.xml:
<bean id="stockPriceService" class="destiny.gwt.stock.server.StockPriceServiceImpl"/>
然后,我想添加另一个服务:Chatroom.gwt.xml(rename-to =“chatroom”),并希望这两个服务可以组合在一个webapp中,并由一个spring4gwt实例提供服务。
这是我的ChatService.java:
@RemoteServiceRelativePath("spring/chatService")
public interface ChatService extends RemoteService
{
public boolean login(String username , String password);
}
spring的app.xml:
<bean id="chatService" class="destiny.gwt.chatroom.server.ChatServiceImpl"/>
<bean id="stockPriceService" class="destiny.gwt.stock.server.StockPriceServiceImpl"/>
至于web.xml:
<servlet-mapping>
<servlet-name>springGwtRemoteServiceServlet</servlet-name>
<url-pattern>/stock/spring/*</url-pattern>
</servlet-mapping>
问题来了!我不知道怎么写一个正确的url-pattern让springGwtRemoteServiceServlet能够同时听到/ stock / spring / *和/ chatroom / spring / *?
StockWatcher模块是rename-to =“stock”,因此每个POST请求都会发布到URI“/ stock / ...”。并且聊天室模块是rename-to =“chatroom”,每个POST都将发布到URI“/ chatroom / ...”。我试着写/*/spring/*
,但徒劳无功,两者都不起作用......
答案 0 :(得分:2)
表达式/*/spring/*
不是spring的有效路径。您可以明确地设置另一个映射,而不是尝试使用通配符(*
):
<servlet-mapping>
<servlet-name>springGwtRemoteServiceServlet</servlet-name>
<url-pattern>/stock/spring/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springGwtRemoteServiceServlet</servlet-name>
<url-pattern>/chatroom/spring/*</url-pattern>
</servlet-mapping>
答案 1 :(得分:1)
试试这个:
<servlet-mapping>
<servlet-name>springGwtRemoteServiceServlet</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
然后:
@RemoteServiceRelativePath("../spring/chatService")