2017-07-26 13 views
0

こんにちは私は、web.xmlの代わりにサーブレットをマップするアノテーションを使用しています。オブジェクト化を使用してデータストアからエンティティを取得しようとしています(私はGoogleのアプリケーションエンジンのjava8バージョンを使用しています)エンティティ(クラス)を登録します。 (コードの下など)私の場合、私が使用していないのweb.xmlObjectifyfilterの注釈

<filter> 
    <filter-name>ObjectifyFilter</filter-name> 
    <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>ObjectifyFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

Question:

I got this error:

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. 
    at com.googlecode.objectify.ObjectifyService.ofy(ObjectifyService.java:44) 

私は、web.xml内のフィルタを客観化しなければならない必要があることを知っています注釈でこのオブジェクト化フィルタを実行するにはどうすればよいですか?

答えて

1

ObjectifyFilterにコードを変更する必要があるため、@WebFilterアノテーションを取得します。独自のサーブレット/関連コードにアノテーションを使用している間も、web.xmlを作成してObjectifyフィルタを定義することができます。

+0

ありがとう<フィルタクラス> com.googlecode.objectify.ObjectifyFilter < /フィルタクラス> \t \t <のfilter-mapping> \t ObjectifyFilter \t /* (エラー404'エラーが発生しています)@Sai Pullabhotla – Prakash

+0

'Error'-com.google.appengine.tools.development.jetty9 .LocalResourceFileServlet doGet 警告:ファイルが見つかりませんでした:/ index – Prakash

+0

welcome-file-listで誤った設定が可能ですか? web.xmlを追加する前に動作していましたか? webappにリソース "/ index"がありますか? –

1

私は、そうObjectifyFilter

@WebFilter(urlPatterns = {"/*"}) 
public class ObjectifyFilterServlet extends ObjectifyFilter { 
} 

を拡張するクラスを作成することで問題を解決し、私はweb.xmlファイルを使用する場合、その私が取得していますコード

<filter> 
<filter-name>ObjectifyFilter</filter-name> 
<filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class> 
</filter> 
<filter-mapping> 
<filter-name>ObjectifyFilter</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 

ため、正常に動作しますが、最初の要求の場合はError 404です。 ObjectifyFilterを継承したシンプルなクラスを作成しました。この問題を解決しました。他の解決策がある場合は、それらの情報も共有してください。 \t ` \t \t ObjectifyFilter(コードの下)web.xml``で客観化フィルタを指定した後