【问题标题】:Guice and GWT problem - can't find GWT.rpcGuice 和 GWT 问题 - 找不到 GWT.rpc
【发布时间】:2010-04-28 14:29:07
【问题描述】:

我用简单的服务构建了一个简单的联系人管理器应用程序,它确实有效。 然后我决定使用 Guice 来管理我的服务和实现。 我还将 mvp4g 插件用于 MVP 设计模式。 我在他的blog 上关注了 Eric Burke 的示例,我的代码如下所示:
ContactService.java

@RemoteServiceRelativePath("GWT.rpc")
    public interface ContactService extends RemoteService {

    public void saveContact(Contact c);

    public List<Contact> listContacts();
}

ContactServletModule.java:

@Singleton
public class ContactServletModule extends ServletModule{

    private static String SQL_MAP_CONFIG = "org/yuri/SqlMapConfig.xml";
    private SqlSessionFactory factory = null;

    @Provides
    public SqlSessionFactory getSqlSessionFactory(){
        if(this.factory == null){
            try {
                /*
                 * Create new factory
                 */
                Reader r = Resources.getResourceAsReader(SQL_MAP_CONFIG);
                this.factory = new SqlSessionFactoryBuilder().build(r);
            } catch (IOException ex) {
                /*
                 * do nothing, factory is null still
                 */
            } finally{
                return this.factory;
            }
        }
        else{
            return this.factory;
        }
    }

    @Override
    protected void configureServlets() {
        serve("/YuriContactManager/GWT.rpc").with(GuiceRemoteServiceServlet.class);

        bind(ContactService.class).to(ContactServiceImpl.class);
    }
}

MyGuiceContextListener.java

public class MyGuiceContextListener extends GuiceServletContextListener {

    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new ContactServletModule());
    }
}

但是当我启动我的应用程序并尝试通过调用 listContacts() 列出联系人时,tomcat 告诉我找不到 GWT RPC(确切地说:请求的资源 (/YuriContactManager/org.yuri.ContactManager/GWT. rpc) 不可用。)我的 web.xml 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <filter>
        <filter-name>guiceFilter</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/*</url-pattern>

    </filter-mapping>
    <listener>
        <listener-class>org.yuri.server.MyGuiceContextListener</listener-class>
    </listener>
    <welcome-file-list>
        <welcome-file>welcomeGWT.html</welcome-file>
    </welcome-file-list>
</web-app>

任何人有类似的问题或知道可能出了什么问题?

【问题讨论】:

    标签: gwt mvp guice gwt-rpc


    【解决方案1】:

    发现错误:) 在 ContactServletModule 中服务路径需要修改为"/org.yuri.YuriContactManager/GWT.rpc" - 我认为原因是我也在使用 mvp4g 框架,但我不确定。

    【讨论】:

      猜你喜欢
      • 2011-09-07
      • 2012-03-13
      • 1970-01-01
      • 2011-09-02
      • 2012-04-05
      • 1970-01-01
      • 2022-04-20
      • 2011-02-16
      • 1970-01-01
      相关资源
      最近更新 更多