use of cn.taketoday.web.session.MemSessionRepository in project today-infrastructure by TAKETODAY.
the class WebApplicationContextUtils method registerWebApplicationScopes.
/**
* Register web-specific scopes ("request", "session", "globalSession", "application")
* with the given BeanFactory, as used by the WebServletApplicationContext.
*
* @param beanFactory the BeanFactory to configure
* @param sc the ServletContext that we're running within
*/
public static void registerWebApplicationScopes(ConfigurableBeanFactory beanFactory, @Nullable ServletContext sc) {
SessionManager sessionManager = BeanFactoryUtils.find(beanFactory, SessionManager.BEAN_NAME, SessionManager.class);
if (sessionManager == null) {
sessionManager = new DefaultSessionManager(new MemSessionRepository(new SessionEventDispatcher(), new SecureRandomSessionIdGenerator()), null);
}
beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope());
beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(sessionManager));
if (sc != null) {
ServletContextScope appScope = new ServletContextScope(sc);
beanFactory.registerScope(WebApplicationContext.SCOPE_APPLICATION, appScope);
// Register as ServletContext attribute, for ContextCleanupListener to detect it.
sc.setAttribute(ServletContextScope.class.getName(), appScope);
}
beanFactory.registerDependency(HttpSession.class, new SessionObjectSupplier());
beanFactory.registerDependency(ServletRequest.class, new RequestObjectSupplier());
beanFactory.registerDependency(ServletResponse.class, new ResponseObjectSupplier());
beanFactory.registerDependency(ServletContext.class, sc);
}
Aggregations