开发者

Guice and GWT problem - can't find GWT.rpc

开发者 https://www.devze.com 2022-12-28 06:15 出处:网络
I build a simple contact manager app with simple service and it did work. Then I decided I want to use Guice for managing my services and implementations.

I build a simple contact manager app with simple service and it did work. Then I decided I want to use Guice for managing my services and implementations. I also use mvp4g plugin for MVP design pattern. I followed the exmaple of Eric Burke on his blog, and my code looks like that:

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

But when when I start my app and try to list contacts by calling listContacts(), tomcat tells me that GWT RPC can't be found (exactly: The requested resource (/YuriContactManager/org.yuri.ContactManager/GWT.rpc) is not available.) My web.xml looks like that:

<?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>

Any one had similar problem or has any idea what might be wrong?


found the error :) In ContactServletModule serve path needs to be modified to "/org.yuri.YuriContactManager/GWT.rpc" - I think the reason why is that I'm also using mvp4g framework, but I'm not sure.

0

精彩评论

暂无评论...
验证码 换一张
取 消