package server;
import javax.servlet.ServletContext;
import javax.ws.rs.core.Context;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import server.config.SpringConfigInitializer;
public class SpringAwareResource {
@Context
public void setContext(ServletContext sc) {
autowire(sc);
}
public void autowire(ServletContext sc) {
autowire(sc, this);
}
public static void autowire(ServletContext sc, Object target) {
AnnotationConfigWebApplicationContext context = (AnnotationConfigWebApplicationContext) sc
.getAttribute(SpringConfigInitializer.SPRING_CONTEXT);
context.getBeanFactory().autowireBean(target);
}
}