【发布时间】:2017-03-18 22:17:27
【问题描述】:
我正在尝试在会话范围内创建一个 Spring bean:
<bean id="myClass" class="com.test.Myclass scope="session" />
当我尝试从 servlet 过滤器中的 ApplicationContext 获取类时,如下所示:
WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
Myclass obj = (Myclass)applicationContext.getBean("myClass");
我收到以下错误:java.lang.IllegalStateException: No Scope
registered for scope name 'session'
如果我将范围定义为prototype,我没有任何问题!如何从 applicationContext 检索会话范围的 spring bean?
【问题讨论】:
-
贴出完整代码