Hello,
Im programming a Webapplication using Jsf and Spring ...
I defined my Beans for Test in the following way:
<bean class="com.TestBean"
name="testBean" scope="session">
<aop:scoped-proxy/>
<property name="testProperty" >
<ref bean="testPropertySpec" />
</property>
</bean>
<bean id="testPropertySpec" class="com.TestProperty" >
</bean>
I think refered to the Spring 2.0.6 documentation this is correctly.
My purpose of using session is to set some user specific Properties for the Session. This I make depending on the first Request:
public void doTest(ServletRequest request){
WebApplicationContext context = org.springframework.web.context.support.
WebApplicationContextUtils.getRequiredWebApplicati onContext( ((HttpServletRequest)request).getSession().getServ letContext());
com.TestBean testBean = (com.TestBean) context.getBean("testBean");
com.TestProperty prop = (com.TestProperty) context.getBean("testPropertySpec");
testBean.setTestProperty(prop);
}
The Problem is that:
testBean.setTestProperty(prop);
creates a new instance of my TestBean Object and not use the once created on startup and getted in line: com.TestBean testBean = (com.TestBean) context.getBean("testBean"); . If i use the TestBean in the Application the setted Value (prop) is not in the TestBean. -> logical because the setter was invoked on the new Instance of TestBean.
But why Spring creates a new instance in my Case. I defined TestBean on session Scope and call a Method on this Object. If I had understand it correctly the call of setTestProperty should not create a new object an call this method on that Object.
Any Ideas?


Reply With Quote
