How to inject ServletContext for JUnit tests with Spring?

Posted by Juri Glass on Stack Overflow See other posts from Stack Overflow or by Juri Glass
Published on 2010-04-20T11:40:02Z Indexed on 2010/04/20 11:43 UTC
Read the original article Hit count: 289

Filed under:
|
|
|
|

Hi

I want to unit test a RESTful interface written with Apache CXF.

I use a ServletContext to load some resources, so I have:

@Context
private ServletContext servletContext;

If I deploy this on Glassfish, the ServletContext is injected and it works like expected. But I don't know how to inject the ServletContext in my service class, so that I can test it with a JUnit test.

I use Spring 3.0, JUnit 4, CXF 2.2.3 and Maven.

© Stack Overflow or respective owner

Related posts about java

Related posts about spring