AppFuse で基本的なアプリケーション シェルを作成し、 AppFuse のチュートリアルに従って、Jax-RS で単純な RESTful サービスを作成しました。それはうまくいきます。を呼び出すhttp://localhost:8080/services/api/persons
と、適切なデータを含む JSON 形式の文字列として Person オブジェクトのコレクションが返されます。
Appfuse によって公開された RESTful サービス内から ServletRequest
およびオブジェクトにアクセスしたいと考えています(これらのオブジェクトを必要とする別のライブラリを使用するため)。ServletResponse
@Context アノテーションを追加することでそれが可能になると思います。たとえば、このStackOverflowの投稿と このフォーラムの投稿に従ってください。
しかし、@Context タグ (以下を参照) を追加すると、問題なくコンパイルされますが、サーバーの再起動時に例外がスローされます (下部に添付)。
の宣言は次の@WebService
とおりです。
@WebService
@Path("/persons")
public interface PersonManager extends GenericManager<Person, Long> {
@Path("/")
@GET
@Produces(MediaType.APPLICATION_JSON)
List<Person> read();
...
}
@Context
そして、これが私がアノテーションを呼び出すと思う実装クラスです:
@Service("personManager")
public class PersonManagerImpl extends GenericManagerImpl<Person, Long> implements PersonManager {
PersonDao personDao;
@Context ServletRequest request; // Exception thrown on launch if this is present
@Context ServletContext context; // Exception thrown on launch of this is present
...
}
うまくいけば、それを機能させるために含めるもの、またはServletRequestを取得することは不可能であることを理解するために、単純なものが欠けていることを願っています....手がかりは大歓迎です。
これを IntelliJ の Tomcat で実行しています。
=== 例外スタック トレース (切り捨て) ===
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'serviceBeans' threw exception; nested exception is java.lang.RuntimeException: java.lang.NullPointerException
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
... 37 more