간단한 서비스로 간단한 연락처 관리자 앱을 만들고 작동했습니다. 그런 다음 Guice를 사용하여 서비스 및 구현을 관리하기로 결정했습니다. MVP 디자인 패턴 용 mvp4g 플러그인도 사용합니다. 나는 그의 blog 에릭 버크의 exmaple을 따라, 그리고 내 코드는 다음과 같습니다
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>
하나를 하나는 비슷한 문제가 있었거나 무엇이 잘못되었을 지 모릅니다.