Hi, folks,
a couple of questions from a Spring MVC newbie...
First, I have a problem trying to inject a session scope bean into a controller.
Here's the bean config:
Controller class:Code:<bean id="userSessionContainer" class="UserSessionContainerImpl" scope="session"> <aop:scoped-proxy /> </bean> <bean id="loginController" class="com.condosmart.web.controller.LoginController"> ... <property name="userSessionContainer" ref="userSessionContainer" /> ... </bean>
And now I want to display, say, the name of the Principal in a jsp:Code:private UserSessionContainer userSessionContainer; public void setUserSessionContainer(UserSessionContainer userSessionContainer) { this.userSessionContainer = userSessionContainer; } protected ModelAndView onSubmit(Object command, BindException errors) throws Exception { //... (userByLogin is loaded here) userSessionContainer.setPrincipal(userByLogin); //... }
and nothing is displayed!Code:${userSessionContainer.principal.name}
If instead of using the <aop:scoped-proxy> i+ setter injection I just get the bean from the Application Context:
everything works fine.Code:UserSessionContainer userSessionContainer = (UserSessionContainer)getApplicationContext().getBean(Constants.USER_SESSION_CONTAINER_BEAN_ID); userSessionContainer.setPrincipal(userByLogin);
Actually, I have also noticed that when I try to access any session-scoped bean from a jsp using JSTL:I don't get anything. And as soon as I get this bean somewhere in a controllerCode:${sessionBean.blah}JSTL tags do get it.Code:applicaitonContext.getBean("sesionBeanId")
I am definitely missing something here... any advice is greatly appreciated.
Yours sincerely,
Andrey.


Reply With Quote
