Session Listener in Spring Mvc Google app engine

2019-07-22 08:56发布

I am using Google App Engine, spring mvc and spring jpa dao. In my application i want to delete an entry from the database when session is destroyed. So i am using session listeners which actually wants to deletes an entry from the database through spring dao bean.

Here is my code in session listener

@Override
public void sessionDestroyed(HttpSessionEvent se) {
//get entry from session and now remove entry from database
getMyDao(se).delete(entry);
}

private MyDao getMyDao(HttpSessionEvent sessionEvent){

     HttpSession session = sessionEvent.getSession();

    ApplicationContext ctx = 
          WebApplicationContextUtils.
                getWebApplicationContext(session.getServletContext());

    MyDao dao = 
                (MyDao) ctx.getBean("myDao");

    return dao;
}

I am getting the below error when i try deleting

java.lang.NullPointerException: No API environment is registered for this thread. at com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppId(DatastoreApiHelper.java:108) at com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppIdNamespace(DatastoreApiHelper.java:118) at com.google.appengine.api.datastore.Query.(Query.java:112) at org.datanucleus.store.appengine.query.DatastoreQuery.validate(DatastoreQuery.java:794) at org.datanucleus.store.appengine.query.DatastoreQuery.performExecute(DatastoreQuery.java:225) at org.datanucleus.store.appengine.query.JPQLQuery.performExecute(JPQLQuery.java:80)

Can any one please tell me why api environment is not registered when i invoke from session listener?

1条回答
混吃等死
2楼-- · 2019-07-22 09:40

Google App Engine Doesn't support session listeners. Session listeners may get invoke in local, but No API environment is registered for this thread. In production listeners will not even invoke.

查看更多
登录 后发表回答