简体   繁体   English

春季会议范围

[英]Spring session Scope

I am trying to create a Spring bean in session scope: 我试图在会话范围内创建一个Spring bean:

<bean id="myClass" class="com.test.Myclass scope="session" />

When I try to get the class from ApplicationContext in a servlet filter, like this: 当我尝试从Servlet过滤器中的ApplicationContext获取类时,如下所示:

WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
Myclass obj = (Myclass)applicationContext.getBean("myClass");

I get the following error: java.lang.IllegalStateException: No Scope registered for scope name 'session' 我收到以下错误: java.lang.IllegalStateException: No Scope registered for scope name 'session'

I don't have any issues if I define the scope as prototype ! 如果将范围定义为prototype我没有任何问题! How can I retrieve the session-scope spring bean from applicationContext ? 如何从applicationContext检索会话范围的Spring bean?

I already answered that question before, look here how to define session scope bean: 我之前已经回答了这个问题,请看这里如何定义会话范围bean:

Spring autowireing a session scope bean in AuthenticationSuccessHandler is not working Spring在AuthenticationSuccessHandler中自动连接会话作用域bean不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM