title: Failed to create an instance of Service via deferred binding
body: <p>I have been trying to build a GWT / Google App Engine web app using the <a href="http://code.google.com/p/mvp4g/" rel="noreferrer">mvp4g framework</a>.</p>
  <p>I keep getting an error about <strong>Failing to create an instance of my Service via deferred binding</strong>.</p>
  <p>My Acebankroll.gwt.xml file looks like:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;module rename-to='acebankroll'&gt;
      &lt;inherits name='com.google.gwt.user.User'/&gt;
      &lt;inherits name=&quot;com.google.gwt.i18n.I18N&quot;/&gt;
      &lt;inherits name='com.google.gwt.user.theme.standard.Standard'/&gt;  
      &lt;inherits name='com.mvp4g.Mvp4gModule'/&gt;
      &lt;entry-point class='com.softamo.acebankroll.client.AceBankroll'/&gt;
       &lt;source path='client'/&gt;  
  &lt;/module&gt;
  </code></pre>
  <p>My Entry Module looks like:</p>
  <pre><code>public class AceBankroll implements EntryPoint {
      public void onModuleLoad() {
          Mvp4gModule module = (Mvp4gModule)GWT.create( Mvp4gModule.class );
          module.createAndStartModule();
          RootPanel.get().add((Widget)module.getStartView());
      }
  }
  </code></pre>
  <h1>Error Trace</h1>
  <p>I post the complete error trace as an answer.</p>
  <h1>FAQ and Trials</h1>
  <p>I have read that the next list of common mistakes may cause this error:</p>
  <ul>
  <li><p>The ServiceAsync interfaces have methods with return values. This is <em>wrong</em>, all methods need to return void.</p>
  </li>
  <li><p>The Service interfaces don't extend the RemoteService interface.</p>
  </li>
  <li><p>The methods in the ServiceAsync interfaces miss the final argument of AsyncCallback.</p>
  </li>
  <li><p>The methods on the two interfaced, ExampleService and ExampleServiceAsync, don't match up exactly (other than the return value and AsyncCallback argument)</p>
  </li>
  </ul>
  <p>I have checked all the above conditions and did not find the problem.</p>
  <h2>How do you insert your services in the presenters?</h2>
  <p>Here is a snippet illustrating how I do inject the service in my presenter classes.</p>
  <pre><code>protected MainServiceAsync service = null;
  @InjectService
  public void setService( MainServiceAsync service ) {
      this.service = service;
  }
  </code></pre>
  <h2>Do you have the required libraries?</h2>
  <p>Yes, I have commons-configuration-1.6.jar, commons-lang-2.4.jar and mvp4g-1.1.0.jar in my lib directory.</p>
  <h2>Does your project compiles?</h2>
  <p>Yes, it does compile. I use Eclipse with GWT/Google App Engine plugin. Next I post my .classpath</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;classpath&gt;
      &lt;classpathentry kind=&quot;src&quot; path=&quot;src&quot;/&gt;
      &lt;classpathentry kind=&quot;src&quot; output=&quot;test-classes&quot; path=&quot;test&quot;/&gt;
      &lt;classpathentry kind=&quot;con&quot; path=&quot;com.google.appengine.eclipse.core.GAE_CONTAINER&quot;/&gt;
      &lt;classpathentry kind=&quot;con&quot; path=&quot;com.google.gwt.eclipse.core.GWT_CONTAINER&quot;/&gt;
      &lt;classpathentry kind=&quot;con&quot; path=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot;/&gt;
      &lt;classpathentry kind=&quot;lib&quot; path=&quot;lib/commons-configuration-1.6.jar&quot;/&gt;
      &lt;classpathentry kind=&quot;lib&quot; path=&quot;lib/commons-lang-2.4.jar&quot;/&gt;
      &lt;classpathentry kind=&quot;lib&quot; path=&quot;lib/mvp4g-1.1.0.jar&quot;/&gt;
      &lt;classpathentry kind=&quot;lib&quot; path=&quot;test/lib/emma.jar&quot;/&gt;
      &lt;classpathentry kind=&quot;lib&quot; path=&quot;test/lib/junit-4.5.jar&quot;/&gt;
      &lt;classpathentry kind=&quot;lib&quot; path=&quot;C:/Users/sdelamo/Programms/eclipse/plugins/com.google.appengine.eclipse.sdkbundle.1.3.1_1.3.1.v201002101412/appengine-java-sdk-1.3.1/lib/testing/appengine-testing.jar&quot;/&gt;
      &lt;classpathentry kind=&quot;lib&quot; path=&quot;C:/Users/sdelamo/Programms/eclipse/plugins/com.google.appengine.eclipse.sdkbundle.1.3.1_1.3.1.v201002101412/appengine-java-sdk-1.3.1/lib/impl/appengine-api.jar&quot;/&gt;
      &lt;classpathentry kind=&quot;lib&quot; path=&quot;C:/Users/sdelamo/Programms/eclipse/plugins/com.google.appengine.eclipse.sdkbundle.1.3.1_1.3.1.v201002101412/appengine-java-sdk-1.3.1/lib/impl/appengine-api-labs.jar&quot;/&gt;
      &lt;classpathentry kind=&quot;lib&quot; path=&quot;C:/Users/sdelamo/Programms/eclipse/plugins/com.google.appengine.eclipse.sdkbundle.1.3.1_1.3.1.v201002101412/appengine-java-sdk-1.3.1/lib/impl/appengine-api-stubs.jar&quot;/&gt;
      &lt;classpathentry kind=&quot;lib&quot; path=&quot;C:/Users/sdelamo/Programms/eclipse/plugins/com.google.appengine.eclipse.sdkbundle.1.3.1_1.3.1.v201002101412/appengine-java-sdk-1.3.1/lib/impl/appengine-local-runtime.jar&quot;/&gt;
      &lt;classpathentry kind=&quot;output&quot; path=&quot;war/WEB-INF/classes&quot;/&gt;
  &lt;/classpath&gt;
  </code></pre>
  <h1>Are your Bean Serializable?</h1>
  <p>Yes, they are serializable. They implements the next interface:</p>
  <pre><code>public interface BasicBean extends Serializable  {
      public String getId();      
      public void copy(BasicBean ob); 
  }
  </code></pre>
  <p>They all have an empty argument constructor. Some of them have two constructors. One without arguments and one with arguments.</p>
  <p>Some of them implement this interface</p>
  <pre><code>public interface NameObject extends BasicBean, BaseOwnedObject, Comparable&lt;NameObject&gt;   { 
      public String getName();
      public void setName(String name);       
      public abstract int compareTo(NameObject ob);
  }
  </code></pre>
  <p>Can the Comparable cause problems?</p>
  <h1>How does your service code looks like?</h1>
  <p>I post my service code:</p>
  <h2>MainService</h2>
  <pre><code>@RemoteServiceRelativePath( &quot;main&quot; )
  public interface MainService extends RemoteService {
      public List&lt;UserBean&gt; getUsers();    
      public void deleteUser(UserBean user);    
      public void createUser(UserBean user);    
      public void updateUser( UserBean user );        
      public String authenticate(String username, String password);       
      public boolean isSessionIdStillLegal(String sessionId);     
      public void signOut();      
      public boolean userAlreadyExists(String email);     
      public UserBean getByEmail(String email);       
      public void confirmUser(String email);          
      public UserBean getUserById(String id);
  }
  </code></pre>
  <h2>MainServiceAsync</h2>
  <pre><code>public interface MainServiceAsync {
      public void getUsers(AsyncCallback&lt;List&lt;UserBean&gt;&gt; callback);    
      public void deleteUser(UserBean user, AsyncCallback&lt;Void&gt; callback);    
      public void createUser(UserBean user, AsyncCallback&lt;Void&gt; callback);    
      public void updateUser( UserBean user, AsyncCallback&lt;Void&gt; callback);       
      public void authenticate(String username, String password, AsyncCallback&lt;String&gt; callback);     
      public void isSessionIdStillLegal(String sessionId, AsyncCallback&lt;Boolean&gt; callback);       
      public void signOut(AsyncCallback&lt;Void&gt; callback);      
      public void userAlreadyExists(String email, AsyncCallback&lt;Boolean&gt; callback);       
      public void getByEmail(String email, AsyncCallback&lt;UserBean&gt; callback );            
      public void confirmUser(String email, AsyncCallback&lt;Void&gt; callback );           
      public void getUserById(String id, AsyncCallback&lt;UserBean&gt; callback);
  }
  </code></pre>
  <h2>Basic Bean</h2>
  <pre><code>import java.io.Serializable;    
  public interface BasicBean extends Serializable  {
      public String getId();      
      public void copy(BasicBean ob); 
  }
  </code></pre>
  <h2>User Bean</h2>
  <pre><code>@PersistenceCapable(identityType = IdentityType.APPLICATION)
  public class UserBean implements BasicBean {
      @PrimaryKey
      @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
      protected Long ident;       
      @Persistent
      private String name = null;     
      @Persistent
      private String email = null;        
      @Persistent
      private boolean confirmed = false;      
      @Persistent
      private String password = null;
      
      public UserBean() { }
      
      public String getId() {
          if( ident == null ) return null;
          return ident.toString();
      }
      public void setId(String id) {
          this.ident = Long.parseLong(id);
      }           
      public String getEmail( ) { return email; }
      public void setEmail(String email) { this. email = email; }     
      public String getName() { return name; }
      public void setName(String name) { this. name = name; }     
      public String getPassword() { return password; }    
      public void setPassword(String password) {  this.password = password;}      
      public boolean isConfirmed() { return confirmed;}
      public void setConfirmed(boolean confirmed) {this.confirmed = confirmed;}       
      public void copy(BasicBean ob) {
           UserBean user = (UserBean) ob;
          this.name = user.name;
          this.email = user.email;
          this.password = user.password;      
      }
  }
  </code></pre>
  <p>Next I post an extract of web.xml<br />
  <strong>Note. I have 7 other services. I am using the module functionality of MVP4G. I have other servlets defined for each module in web.xml</strong></p>
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;mainServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.softamo.acebankroll.server.MainServiceImpl&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;mainServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/acebankroll/main&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  <h2>Server</h2>
  <h3>BaseServiceImpl</h3>
  <pre><code>public abstract class BaseServiceImpl extends RemoteServiceServlet {
      protected Map users = new HashMap();
      protected static final MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
      protected static final Logger log = Logger.getLogger(BaseServiceImpl.class.getName());    
      protected String getSessionId() {
          return getThreadLocalRequest().getSession().getId();
      }    
      protected String getCurrentUserId() {
          String id = getSessionId();
          UserBean user = (UserBean) users.get(id);
          if(user!=null) 
              return user.getId();
          return null;
      }    
      protected void saveBaseObject(BasicBean ob) {
          PersistenceManager pm = JdoUtil.getPm();
          String sessionId = getSessionId();      
          UserBean user = (UserBean) users.get(sessionId);
          if(user!=null) {
              String user_id = user.getId();
              ((BaseOwnedObject)ob).setUserId(user_id);
              pm.makePersistent(ob);
          }           
      }    
      protected void deleteBaseObject(Class classname, String id) {
          PersistenceManager pm = JdoUtil.getPm();                
          pm.deletePersistent( pm.getObjectById(classname, Long.parseLong(id) ));     
      }    
      protected List getAll(Class class_name) {
          PersistenceManager pm = JdoUtil.getPm();
          pm.setDetachAllOnCommit(true);
  
          Query q = pm.newQuery(class_name);          
          if(q==null) 
              return new ArrayList&lt;BasicBean&gt;();
          q.setFilter(&quot;userId == userIdParam&quot;);
          q.declareParameters(&quot;String userIdParam&quot;);          
          String userId = getCurrentUserId();
          return (List) q.execute(userId);
      }    
      public boolean isSessionIdStillLegal(String sessionId) {
          return (users.containsKey(sessionId))? true : false;
      }    
      public void signOut() {
          String id = getSessionId();
          synchronized(this) {
              users.remove(id);
          }
      }    
      public BasicBean getObjectById(Class classname, String id) {
          BasicBean result = null;
          PersistenceManager pm = JdoUtil.getPm();
          pm.setDetachAllOnCommit(true);
          result = pm.getObjectById(classname, Long.parseLong(id) );
          return result;
      }
  }
  </code></pre>
  <h3>MainServiceImpl</h3>
  <pre><code>public class MainServiceImpl extends BaseServiceImpl implements MainService {       
      public MainServiceImpl() {}     
      public String authenticate(String username, String password) {
          PersistenceManager pm = JdoUtil.getPm();
  
          UserBean user = getByEmail(username);
          if(user==null || !user.isConfirmed())
              return null;
          String hashFromDB = user.getPassword();
          boolean valid = BCrypt.checkpw(password, hashFromDB);
          if(valid) { 
              String id = getSessionId();
              synchronized( this ) {
                  users.put(id, user) ;
              }
              return id;  
          }
          return null;
      }    
      public void deleteUser(UserBean user) {
          deleteBaseObject(UserBean.class, user.getId());
      }
      public List&lt;UserBean&gt; getUsers() {
          PersistenceManager pm = JdoUtil.getPm();
          pm.setDetachAllOnCommit(true);
          Query q = pm.newQuery(UserBean.class);          
          if(q==null) 
              return new ArrayList&lt;UserBean&gt;();           
          return (List) q.execute();      
      }    
      public boolean userAlreadyExists(String email) {
          return (getByEmail(email)!=null) ? true : false;        
      }    
      public void updateUser(UserBean object) {
          saveBaseObject(object);
      }    
      public void confirmUser(String email) {
          PersistenceManager pm = JdoUtil.getPm();        
          UserBean user = getByEmail(email);
          if(user!=null) {
              user.setConfirmed(true);
              pm.makePersistent(user);
          }   
      }    
      public void createUser(UserBean user) {
          PersistenceManager pm = JdoUtil.getPm();
          String sessionId = getSessionId();
          // Only store it if it does not exists
          if( (getByEmail(user.getEmail()))==null) {
              String hash = BCrypt.hashpw(user.getPassword(), BCrypt.gensalt());
              user.setPassword(hash);
              pm.makePersistent(user);
              synchronized( this ) {
                  users.put(sessionId, user);              
              }           
          }       
      }    
      public UserBean getByEmail(String email) {
          return new MyAccountServiceImpl().getByEmail(email);
      }    
      public UserBean getUserById(String id) {
          return new MyAccountServiceImpl().getUserById(id);
      }
  }
  </code></pre>
  <h1>SOLUTION</h1>
  <p>Apparently the Google App Engine Annotations in my Bean classes were causing the problem. Removing the annotation from the client side code solved the issue. What I do know if I have the classes with the JDO notation in the server side. That it is to say the beans are plain data transfere object which get cloned into object with JDO annotations in the server side.</p>
  <p>I am literally stacked. I do not know what to try. Any help is really appreciated!</p>