0
我使用簡單的服務構建了一個簡單的聯繫人管理器應用程序,它確實有效。 然後我決定使用Guice來管理我的服務和實現。 我也使用MVP設計模式的mvp4g插件。 我跟着埃裏克·伯克〔實施例對他blog,我的代碼看起來像這樣:
ContactService.javaGuice和GWT問題 - 無法找到GWT.rpc
@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>
任何一個人有類似的問題,或有什麼想法可能是錯的?