无法通过延迟绑定创建服务实例 [英] Failed to create an instance of Service via deferred binding

查看:260
本文介绍了无法通过延迟绑定创建服务实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 mvp4g框架构建GWT / Google App Engine网络应用程序>。



我一直收到关于无法通过延迟绑定创建我的服务实例的错误。



我的Acebankroll.gwt.xml文件如下所示:

 <?xml version =1.0encoding = UTF-8 >?; 
< module rename-to ='acebankroll'>
<继承了name ='com.google.gwt.user.User'/>
<继承了name =com.google.gwt.i18n.I18N/>
<继承了name ='com.google.gwt.user.theme.standard.Standard'/>
<继承名称='com.mvp4g.Mvp4gModule'/>
< entry-point class ='com.softamo.acebankroll.client.AceBankroll'/>
< source path ='client'/>
< / module>

My Entry Module看起来像:

 $ $ $ $ $ $'$ $ $ $ $ $ $ $ $ $ $ $ $' 
module.createAndStartModule();
RootPanel.get()。add((Widget)module.getStartView());




$ h $错误跟踪

我将完整的错误追踪作为答案发布。



常见问题和试用



I已经阅读下一个常见错误列表可能会导致此错误:


  • ServiceAsync接口具有带返回值的方法。这是错误,所有方法都需要返回void。


  • 服务接口不扩展RemoteService接口。

    >

  • ServiceAsync接口中的方法错过了AsyncCallback的最后一个参数。两个接口的ExampleService和ExampleServiceAsync完全不匹配(除了返回值和AsyncCallback参数)


    我已经检查了所有上述条件并没有发现问题。

    你如何在演示者中插入你的服务?



    下面是一段代码,在我的主持人课程中提供服务。

     受保护的MainServiceAsync服务= null; 
    @InjectService
    public void setService(MainServiceAsync service){
    this.service = service;

    $ / code $ / pre

    你有需要的库吗?



    是的,我的lib目录中有commons-configuration-1.6.jar,commons-lang-2.4.jar和mvp4g-1.1.0.jar。

    你的项目是否编译?



    是的,它编译。我使用带有GWT / Google App Engine插件的Eclipse。接下来我发布.classpath

     <?xml version =1.0encoding =UTF-8?> 
    < classpath>
    < classpathentry kind =srcpath =src/>
    < classpathentry kind =srcoutput =test-classespath =test/>
    < classpathentry kind =conpath =com.google.appengine.eclipse.core.GAE_CONTAINER/>
    < classpathentry kind =conpath =com.google.gwt.eclipse.core.GWT_CONTAINER/>
    < classpathentry kind =conpath =org.eclipse.jdt.launching.JRE_CONTAINER/>
    < classpathentry kind =libpath =lib / commons-configuration-1.6.jar/>
    < classpathentry kind =libpath =lib / commons-lang-2.4.jar/>
    < classpathentry kind =libpath =lib / mvp4g-1.1.0.jar/>
    < classpathentry kind =libpath =test / lib / emma.jar/>
    < classpathentry kind =libpath =test / lib / junit-4.5.jar/>
    < classpathentry kind =libpath =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.jar/>
    < classpathentry kind =libpath =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 /应用服务引擎-api.jar文件/>
    < classpathentry kind =libpath =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 /应用服务引擎-API-labs.jar/>
    < classpathentry kind =libpath =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 /应用服务引擎-API-stubs.jar/>
    < classpathentry kind =libpath =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 /应用服务引擎和本地runtime.jar/>
    < classpathentry kind =outputpath =war / WEB-INF / classes/>
    < / classpath>



    您的Bean可序列化吗?



    是,它们是可序列化的。它们实现了下一个接口:

      public interface BasicBean extends Serializable {
    public String getId();
    public void copy(BasicBean ob);
    }

    它们都有一个空的参数构造函数。其中一些有两个构造函数。一个没有参数,一个有参数。



    其中一些实现了这个接口

      public interface NameObject extends BasicBean ,BaseOwnedObject,Comparable< NameObject> {
    public String getName();
    public void setName(String name);
    public abstract int compareTo(NameObject ob);
    }

    Comparable是否会导致问题?

    你的服务代码是怎么样的?



    我发布了我的服务代码:

    MainService



      @RemoteServiceRelativePath(main)
    public interface MainService extends RemoteService {
    public List< UserBean> 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);



    $ b $ h $ MainServiceAsync

    $ p公共接口MainServiceAsync {
    public void getUsers(AsyncCallback< List< UserBean>> callback); $ p>
    public void deleteUser(UserBean user,AsyncCallback< Void> callback);
    public void createUser(UserBean user,AsyncCallback< Void> callback);
    public void updateUser(UserBean user,AsyncCallback< Void> callback);
    public void authenticate(String username,String password,AsyncCallback< String> callback);
    public void isSessionIdStillLegal(String sessionId,AsyncCallback< Boolean> callback);
    public void signOut(AsyncCallback< Void> callback);
    public void userAlreadyExists(String email,AsyncCallback< Boolean> callback);
    public void getByEmail(String email,AsyncCallback< UserBean> callback);
    public void confirmUser(String email,AsyncCallback< Void> callback);
    public void getUserById(String id,AsyncCallback< UserBean> callback);

    $ / code>



    基本Bean



      import java.io.Serializable; 
    public interface BasicBean extends Serializable {
    public String getId();
    public void copy(BasicBean ob);

    $ / code>



    用户Bean



    <$
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)$ b public class UserBean implements BasicBean {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    保护Long ident;
    @Persistent
    private String name = null;
    @Persistent
    private String email = null;
    @Persistent
    private boolean confirmed = false;
    @Persistent
    private String password = null;
    $ b $ public UserBean(){}
    $ b $ public String getId(){
    if(ident == null)return null;
    返回ident.toString();
    }
    public void setId(String id){
    this.ident = Long.parseLong(id);
    }
    public String getEmail(){return email; }
    public void setEmail(String email){this。 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 =已确认;}
    public void copy(BasicBean ob){
    UserBean user =(UserBean)ob;
    this.name = user.name;
    this.email = user.email;
    this.password = user.password;


    接下来,我张贴web.xml的摘录>
    注意。我有7个其他服务。我正在使用MVP4G的模块功能。我为web.xml中的每个模块定义了其他servlet

     < servlet> 
    < servlet-name> mainServlet< / servlet-name>
    < servlet-class> com.softamo.acebankroll.server.MainServiceImpl< / servlet-class>
    < / servlet>

    < servlet-mapping>
    < servlet-name> mainServlet< / servlet-name>
    < url-pattern> / acebankroll / main< / url-pattern>
    < / servlet-mapping>



    服务器



    BaseServiceImpl



    pre $ public abstract class BaseServiceImpl extends RemoteServiceServlet {
    protected Map users = new HashMap();
    protected static final MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
    protected static 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();
    返回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);

    查询q = pm.newQuery(class_name);
    if(q == null)
    返回新的ArrayList< BasicBean>();
    q.setFilter(userId == userIdParam);
    q.declareParameters(String userIdParam);
    String userId = getCurrentUserId();
    return(List)q.execute(userId);
    }
    public boolean isSessionIdStillLegal(String sessionId){
    return(users.containsKey(sessionId))?真假;
    }
    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));
    返回结果;


    $ / code $ / pre
    $ b $ h $ MainServiceImpl

      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;
    }
    返回null;
    }
    public void deleteUser(UserBean user){
    deleteBaseObject(UserBean.class,user.getId());
    }
    public List< UserBean> getUsers(){
    PersistenceManager pm = JdoUtil.getPm();
    pm.setDetachAllOnCommit(true);
    Query q = pm.newQuery(UserBean.class);
    if(q == null)
    返回新的ArrayList< UserBean>();
    return(List)q.execute();
    }
    public boolean userAlreadyExists(String email){
    return(getByEmail(email)!= null)?真假;
    }
    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();
    //仅当它不存在时才存储
    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);


    $ b public UserBean getByEmail(String email){
    return new MyAccountServiceImpl()。getByEmail(email);
    }
    public UserBean getUserById(String id){
    return new MyAccountServiceImpl()。getUserById(id);
    }
    }



    解决方案



    显然,我的Bean类中的Google App引擎注释引发了这个问题。从客户端代码中删除注释解决了问题。我所知道的是,如果我在服务器端有JDO符号的类。这就是说,bean是纯数据传输对象,它通过服务器端的JDO注释克隆到对象中。

    我真的被堆叠起来了。我不知道该怎么尝试。如果你的服务方法包含POJO的,他们可能会导致你的问题,他们必须有一个零参数的构造函数或者没有定义构造函数。另外,它们必须实现IsSerializable或Serializable。



    您可以手动创建服务:

      MainServiceAsync服务= GWT.create(MainService.class); 

    也许发布MainService类。



    编辑:



    这是treelogger的输出,延迟绑定失败,当您执行gwt编译时,输出到控制台。如果以托管模式运行,您还可以在devmode控制台中看到此输出。总是检查第一个错误,因为其他错误大部分是由第一个错误引起的。

     编译模块se.pathed。 defa.DefaultGwtProject 
    扫描其他依赖项:file:/ C:/Users/Patrik/workspace/skola-workspace/DefaultGwtProject/src/se/pathed/defa/client/DefaultGwtProject.java
    计算所有可能的'se.pathed.defa.client.GreetingService'的重新绑定结果
    重新绑定se.pathed.defa.client.GreetingService
    调用com.google.gwt.dev.javac.StandardGeneratorContext@16c6a55
    为远程服务接口'se.pathed.defa.client.GreetingService'生成客户端代理
    [错误] se.pathed.defa.shared.UserBean不是默认的可实例化的(它必须有一个零参数构造函数或者没有构造函数根本没有)并且没有自定义串行器。 (通过se.pathed.defa.shared.UserBean达到)
    [错误] se.pathed.defa.shared.UserBean没有可用的实例化子类型。 (通过se.pathed.defa.shared.UserBean达成)
    [ERROR]子类型se.pathed.defa.shared.UserBean不是默认的可实例化的(它必须有一个零参数构造函数或根本没有构造函数)和没有自定义序列化程序。 (通过se.pathed.defa.shared.UserBean得到)
    [错误]'file:/ C:/ Users / Patrik / workspace / skola-workspace / DefaultGwtProject / src / se / pathed / defa / client中的错误/DefaultGwtProject.java'
    [错误]第37行:无法通过延迟绑定解析'se.pathed.defa.client.GreetingService'
    扫描其他依赖项:jar:file:/ C:/ eclipse /plugins/com.google.gwt.eclipse.sdkbundle.2.0.3_2.0.3.v201002191036/gwt-2.0.3/gwt-user.jar!/com/google/gwt/core/client/impl/SchedulerImpl.java
    [WARN]以下资源将不会被创建,因为它们从未提交过(您是否忘记调用commit()?)
    [WARN] C:\ Users \Patrik\AppData\Local \Temp\gwtc301646733929273376.tmp\se.pathed.defa.DefaultGwtProject\compiler\se.pathed.defa.client.GreetingService.rpc.log
    [WARN]对于以下类型,生成的源文件从不提交(你忘记调用commit()?)
    [WARN] se .pathed.defa.client.GreetingService_Proxy
    [错误]由于前面的错误而无法继续


    I have been trying to build a GWT / Google App Engine web app using the mvp4g framework.

    I keep getting an error about Failing to create an instance of my Service via deferred binding.

    My Acebankroll.gwt.xml file looks like:

    <?xml version="1.0" encoding="UTF-8"?>
    <module rename-to='acebankroll'>
        <inherits name='com.google.gwt.user.User'/>
        <inherits name="com.google.gwt.i18n.I18N"/>
        <inherits name='com.google.gwt.user.theme.standard.Standard'/>  
        <inherits name='com.mvp4g.Mvp4gModule'/>
        <entry-point class='com.softamo.acebankroll.client.AceBankroll'/>
         <source path='client'/>  
    </module>
    

    My Entry Module looks like:

    public class AceBankroll implements EntryPoint {
        public void onModuleLoad() {
            Mvp4gModule module = (Mvp4gModule)GWT.create( Mvp4gModule.class );
            module.createAndStartModule();
            RootPanel.get().add((Widget)module.getStartView());
        }
    }
    

    Error Trace

    I post the complete error trace as an answer.

    FAQ and Trials

    I have read that the next list of common mistakes may cause this error:

    • The ServiceAsync interfaces have methods with return values. This is wrong, all methods need to return void.

    • The Service interfaces don't extend the RemoteService interface.

    • The methods in the ServiceAsync interfaces miss the final argument of AsyncCallback.

    • The methods on the two interfaced, ExampleService and ExampleServiceAsync, don't match up exactly (other than the return value and AsyncCallback argument)

    I have checked all the above conditions and did not find the problem.

    How do you insert your services in the presenters?

    Here is a snippet illustrating how I do inject the service in my presenter classes.

    protected MainServiceAsync service = null;
    @InjectService
    public void setService( MainServiceAsync service ) {
        this.service = service;
    }
    

    Do you have the required libraries?

    Yes, I have commons-configuration-1.6.jar, commons-lang-2.4.jar and mvp4g-1.1.0.jar in my lib directory.

    Does your project compiles?

    Yes, it does compile. I use Eclipse with GWT/Google App Engine plugin. Next I post my .classpath

    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" output="test-classes" path="test"/>
        <classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER"/>
        <classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="lib" path="lib/commons-configuration-1.6.jar"/>
        <classpathentry kind="lib" path="lib/commons-lang-2.4.jar"/>
        <classpathentry kind="lib" path="lib/mvp4g-1.1.0.jar"/>
        <classpathentry kind="lib" path="test/lib/emma.jar"/>
        <classpathentry kind="lib" path="test/lib/junit-4.5.jar"/>
        <classpathentry kind="lib" path="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"/>
        <classpathentry kind="lib" path="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"/>
        <classpathentry kind="lib" path="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"/>
        <classpathentry kind="lib" path="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"/>
        <classpathentry kind="lib" path="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"/>
        <classpathentry kind="output" path="war/WEB-INF/classes"/>
    </classpath>
    

    Are your Bean Serializable?

    Yes, they are serializable. They implements the next interface:

    public interface BasicBean extends Serializable  {
        public String getId();      
        public void copy(BasicBean ob); 
    }
    

    They all have an empty argument constructor. Some of them have two constructors. One without arguments and one with arguments.

    Some of them implement this interface

    public interface NameObject extends BasicBean, BaseOwnedObject, Comparable<NameObject>   { 
        public String getName();
        public void setName(String name);       
        public abstract int compareTo(NameObject ob);
    }
    

    Can the Comparable cause problems?

    How does your service code looks like?

    I post my service code:

    MainService

    @RemoteServiceRelativePath( "main" )
    public interface MainService extends RemoteService {
        public List<UserBean> 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);
    }
    

    MainServiceAsync

    public interface MainServiceAsync {
        public void getUsers(AsyncCallback<List<UserBean>> callback);    
        public void deleteUser(UserBean user, AsyncCallback<Void> callback);    
        public void createUser(UserBean user, AsyncCallback<Void> callback);    
        public void updateUser( UserBean user, AsyncCallback<Void> callback);       
        public void authenticate(String username, String password, AsyncCallback<String> callback);     
        public void isSessionIdStillLegal(String sessionId, AsyncCallback<Boolean> callback);       
        public void signOut(AsyncCallback<Void> callback);      
        public void userAlreadyExists(String email, AsyncCallback<Boolean> callback);       
        public void getByEmail(String email, AsyncCallback<UserBean> callback );            
        public void confirmUser(String email, AsyncCallback<Void> callback );           
        public void getUserById(String id, AsyncCallback<UserBean> callback);
    }
    

    Basic Bean

    import java.io.Serializable;    
    public interface BasicBean extends Serializable  {
        public String getId();      
        public void copy(BasicBean ob); 
    }
    

    User Bean

    @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;      
        }
    }
    

    Next I post an extract of web.xml
    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

    <servlet>
        <servlet-name>mainServlet</servlet-name>
        <servlet-class>com.softamo.acebankroll.server.MainServiceImpl</servlet-class>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>mainServlet</servlet-name>
        <url-pattern>/acebankroll/main</url-pattern>
    </servlet-mapping>
    

    Server

    BaseServiceImpl

    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<BasicBean>();
            q.setFilter("userId == userIdParam");
            q.declareParameters("String userIdParam");          
            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;
        }
    }
    

    MainServiceImpl

    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<UserBean> getUsers() {
            PersistenceManager pm = JdoUtil.getPm();
            pm.setDetachAllOnCommit(true);
            Query q = pm.newQuery(UserBean.class);          
            if(q==null) 
                return new ArrayList<UserBean>();           
            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);
        }
    }
    

    SOLUTION

    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.

    I am literally stacked. I do not know what to try. Any help is really appreciated!

    解决方案

    If your service methods contains POJO's they can cause you problems, they must have a zero argument constructor or no constructor defined. Also they must implement either IsSerializable or Serializable.

    You can trie to create the service manually with:

    MainServiceAsync service = GWT.create(MainService.class);
    

    And maybe post the MainService classes.

    Edited:

    This is an output from the treelogger with a deferred binding failing, and it is outputed into the console when you do a gwt compile. You can also see this output in the devmode console if you run in hosted mode. Always check the first error, because the others are most of the time caused by the first error.

    Compiling module se.pathed.defa.DefaultGwtProject
       Scanning for additional dependencies: file:/C:/Users/Patrik/workspace/skola-workspace/DefaultGwtProject/src/se/pathed/defa/client/DefaultGwtProject.java
          Computing all possible rebind results for 'se.pathed.defa.client.GreetingService'
             Rebinding se.pathed.defa.client.GreetingService
                Invoking com.google.gwt.dev.javac.StandardGeneratorContext@16c6a55
                   Generating client proxy for remote service interface 'se.pathed.defa.client.GreetingService'
                      [ERROR] se.pathed.defa.shared.UserBean is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via se.pathed.defa.shared.UserBean)
                      [ERROR] se.pathed.defa.shared.UserBean has no available instantiable subtypes. (reached via se.pathed.defa.shared.UserBean)
                         [ERROR]    subtype se.pathed.defa.shared.UserBean is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via se.pathed.defa.shared.UserBean)
       [ERROR] Errors in 'file:/C:/Users/Patrik/workspace/skola-workspace/DefaultGwtProject/src/se/pathed/defa/client/DefaultGwtProject.java'
          [ERROR] Line 37:  Failed to resolve 'se.pathed.defa.client.GreetingService' via deferred binding
       Scanning for additional dependencies: jar:file:/C:/eclipse/plugins/com.google.gwt.eclipse.sdkbundle.2.0.3_2.0.3.v201002191036/gwt-2.0.3/gwt-user.jar!/com/google/gwt/core/client/impl/SchedulerImpl.java
          [WARN] The following resources will not be created because they were never committed (did you forget to call commit()?)
             [WARN] C:\Users\Patrik\AppData\Local\Temp\gwtc301646733929273376.tmp\se.pathed.defa.DefaultGwtProject\compiler\se.pathed.defa.client.GreetingService.rpc.log
          [WARN] For the following type(s), generated source was never committed (did you forget to call commit()?)
             [WARN] se.pathed.defa.client.GreetingService_Proxy
       [ERROR] Cannot proceed due to previous errors
    

    这篇关于无法通过延迟绑定创建服务实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆