Получить текущий запрос в Custom Spring Scope

1

я пишу настраиваемую базу весов в FacesContext Logique,

public class DynamicScope implements Scope{
    @Override
    public Object get(String name, ObjectFactory<?> objectFactory) {
        AbsErpFolder erpFolder = null;
        if (FacesContext.getCurrentInstance()!=null)            
            erpFolder = (AbsErpFolder)FacesUtils.getExternalContext().
getRequestMap().get( ErpFolderKey );
    ............
}  

Теперь мне нужно инициализировать компонент в FileServlet Filter, используя

WebApplicationContext wsc = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
IGenericService erpFileService = (IGenericService) wsc.getBean("erpFileService");

Проблема заключается во время выполнения моего ServletFile, текущий FacesContext имеет значение null (динамическая область не может работать), так как получить текущий запрос?

Теги:
servlets
spring
jsf
request

1 ответ

1
Лучший ответ

ThreadLocal должен делать трюк (определенный в моем первом фильтре)

public static ThreadLocal servletRequestHolder  = new ThreadLocal();
public static HttpServletRequest getCurrentRequest(){
    return (HttpServletRequest) servletRequestHolder.get();
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {
   servletRequestHolder.set( request );
...........
}

Ещё вопросы

Сообщество Overcoder
Наверх
Меню