How to resolve “You have not started an Objectify context” in JUnit?

后端 未结 5 748
旧巷少年郎
旧巷少年郎 2021-01-17 16:55

I\'ve got some Objectify test code running in JUnit and I\'m getting this error:

java.lang.IllegalStateException: You have not started an Objectify context.          


        
5条回答
  •  感情败类
    2021-01-17 17:53

    I was facing the same error and this solusion worked for me

    I have an app based on Endpoints that uses Objectify. When I leave it with the default/automatic scaling, everything works great. Once I enable basic scaling, though, I get the following exception when executing the endpoint method:

    [INFO] java.lang.IllegalStateException: You have not started an Objectify context. You are probably missing the ObjectifyFilter. If you are not running in the context of an http request, see the ObjectifyService.run() method.
    [INFO]  at com.googlecode.objectify.ObjectifyService.ofy(ObjectifyService.java:44)
    [INFO]  at com.myco.myapp.dao.datastore.OfyService.ofy(OfyService.java:62)
    

    The good news is that this goes away when you enable RequestDispatcher support in the web.xml file like so. I think this is a documentation issue, then, but I didn't know if everyone would agree if I edited the Wiki page directly. Here is the proposed web.xml entry, which worked for me:

       
        ObjectifyFilter
        com.googlecode.objectify.ObjectifyFilter
    
    
        ObjectifyFilter
        /*
        REQUEST
        INCLUDE
        FORWARD
    
    

提交回复
热议问题