2010-07-20 63 views
0

我成功地跟随GWT和spring4gwt的教程和改造的StockWatcher的演示在Spring(3.0)功能的服务,通过以下配置:如何让spring4gwt导出多个服务?

的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; 
} 

春天的app.xml:

<bean id="stockPriceService" class="destiny.gwt.stock.server.StockPriceServiceImpl"/> 

然后,我想添加另一个Service:Chatroom.gwt.xml(重命名为=“chatroom”),并希望这两个服务可以合并到一个webapp中,并由一个spring4gwt实例提供服务。

这是我ChatService.java:

@RemoteServiceRelativePath("spring/chatService") 
public interface ChatService extends RemoteService 
{ 
    public boolean login(String username , String password); 
} 

春天的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模式来让springGwtRemoteServiceServlet能够模仿地聆听/ stock/spring/*和/ chatroom/spring/*?

StockWatcher模块被重命名为=“stock”,因此每个POST请求都会发布到URI“/ stock/...”。 Chatroom模块重命名为=“chatroom”,每个POST将发布到URI“/ chatroom/...”。我试着写/*/spring/*,却徒劳无功,无论是不行的......

回答

1

试试这个:

<servlet-mapping> 
    <servlet-name>springGwtRemoteServiceServlet</servlet-name> 
    <url-pattern>/spring/*</url-pattern> 
    </servlet-mapping> 

然后:

@RemoteServiceRelativePath("../spring/chatService") 
2

表达/*/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>