春季会议范围

时间:2016-11-05 00:27:12

标签: spring scope

我正在尝试在会话范围中创建一个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?

1 个答案:

答案 0 :(得分:1)

我之前已经回答了这个问题,请看这里如何定义会话范围bean:

Spring autowireing a session scope bean in AuthenticationSuccessHandler is not working

相关问题