Vote count:
0
I'm very new to Spring and web development in general, so please bear with me if the question seems confused or incomplete...
I'm currently working on a Spring project in which there is a bean I'll call 'requestContext' which holds some commonly used data. This bean is request-scoped, and it appears to get populated by a servelet filter (a child of GenericFilterBean).
I'm trying to access the info held by this bean from another bean (i'll call UserBean) in the preHandle method of a HandlerInterceptor. In UserBean I use @AutoWired to access the bean as below:
@Autowired
private RequestContext requestContext;
Then in one of UserBeans methods I try to access the necessary data. The problem is that the request context contains all null values. I thought there might be some lifecycle issue, being unfamiliar with filters, but using some breakpoints I can see that the filter is executed before the handlerInterceptor, and I can see the request context data being set. That being the case I would expect to at least be able to access it in the preHandle method of the interceptor if not the others.
The rest of the application (including filter, handler interceptor) is all existing/known working code, so I don't think I have any setup issues up to the point where I'm trying to use that bean. There's just some problem with either my expectations, or with how I'm trying to access it.
accessing a request-scoped bean in HandlerIntercaptor
Aucun commentaire:
Enregistrer un commentaire