java - Error in spring when using scoped-proxy beans -
i getting error in spring when trying use session scoped beans, error is:
http status 500 - error creating bean name 'scopedtarget.usuarioautenticado': scope 'session' not active current thread; consider defining scoped proxy bean if intend refer singleton; nested exception java.lang.illegalstateexception: no thread-bound request found: referring request attributes outside of actual web request, or processing request outside of receiving thread? if operating within web request , still receive message, code running outside of dispatcherservlet/dispatcherportlet: in case, use requestcontextlistener or requestcontextfilter expose current request. my configuration is: web.xml:
<servlet> <servlet-name>spring mvc dispatcher servlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value> web-inf/applicationcontext*.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring mvc dispatcher servlet</servlet-name> <url-pattern>/sys/*</url-pattern> </servlet-mapping> <filter> <filter-name>springsecurityfilterchain</filter-name> <filter-class>org.springframework.web.filter.delegatingfilterproxy</filter-class> </filter> <filter-mapping> <filter-name>springsecurityfilterchain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> and bean:
<bean id="usuarioautenticado" class="com.wi.security.usuarioautenticado" scope="session"> <aop:scoped-proxy/> </bean> i have been searching issue , have found add following lines web.xml:
<listener> <listener-class>org.springframework.web.context.request.requestcontextlistener</listener-class> </listener> this solves issue, side effect @scheduled annotated methods running twice, think because spring creating 2 contexts.
reading spring docs says:
dispatcherservlet, requestcontextlistener , requestcontextfilter same thing, namely bind http request object thread servicing request. makes beans request- , session-scoped available further down call chain.
so, don't understand why not working dispatcherservlet configuration. hope can me find solution, new spring. in advance.
got it!
i setting in web.xml contextconfiglocation:
<context-param> <param-name>contextconfiglocation</param-name> <param-value>web-inf/applicationcontext*.xml</param-value> </context-param> and setting again in servlet configuration:
<servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>web-inf/applicationcontext*.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> the solution remove servlet param-value:
<servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value/> </init-param> <load-on-startup>1</load-on-startup> </servlet>
Comments
Post a Comment