PDA

View Full Version : Scope Session Bean Problem



roninken
Mar 3rd, 2008, 03:21 PM
Hi

I am developing a J2EE application with Spring MVC, ZK, and ACEGI, and I have next problem:

I need inject a Session bean (new Spring Scope) in other bean that is not session, (maybe singleton), the applicationContext.xml source is:



<bean id="testBean" class="scope.TestBean" scope="session">
<aop:scoped-proxy/>
</bean>
<bean id="testBean2" class="scope.TestBean2">
<property name="testBean" ref="testBean"/>
</bean>


I set the web.xml file and i put the correspondig listener:



<listener>
<listener-class>
org.springframework.web.context.request.RequestCon textListener
</listener-class>
</listener>


The previous code i think is ok, even, the tomcat server running well, but, when I create the bean Instance whit zk Event:



private ITestBean2 testBean2 = (ITestBean2) SpringUtil.getBean("testBean2");
private ITestBean testBean = testBean2.getTestBean();
public void TestBean()
{
testBean2.setId(1);
testBean.setId(1);
System.out.println("["+testBean2.getClass().getName()+"] Id: "+testBean2.getId());
System.out.println("["+testBean.getClass().getName()+"] Id: "+testBean.getId());
}


the application shows the next error:



3/03/2008 04:16:09 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:764
GRAVE: >>org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.testBean': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
>>java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
>> at org.springframework.web.context.request.RequestCon textHolder.currentRequestAttributes(RequestContext Holder.java:102)
>> at org.springframework.web.context.request.SessionSco pe.get(SessionScope.java:88)
>> at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:285)
>> at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:160)
>> at org.springframework.aop.target.SimpleBeanTargetSou rce.getTarget(SimpleBeanTargetSource.java:33)
>>...


What happen?

Ahh, my english is wrong, excuse me plase.

heikow
Mar 3rd, 2008, 05:07 PM
I think you must configure a RequestContextFilter in your web.xml:


<filter>
<filter-name>requestContextFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilte r</filter-class>
</filter>
<filter-mapping>
<filter-name>requestContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

roninken
Mar 3rd, 2008, 05:45 PM
Thanks, but the RequestContextFilter is in the web.xml file.

I think that are acegi's filters the responsible of problem.

and you?


Please, help me !!

henrichen
Mar 4th, 2008, 09:34 AM
Maybe you want to take a look of this regarding ZK and Spring Framework.
http://www.zkoss.org/javadoc/3.0.3/zkplus/org/zkoss/zkplus/util/ThreadLocalListener.html

roninken
Mar 4th, 2008, 01:03 PM
Thanks, this is the true Solution !!!

henrichen
Mar 4th, 2008, 06:46 PM
Hi roninken,

If you don't use ZK's Modal window, you can "disable" ZK's event thread mechanism entirely (so you don't have to add that ThreadLocalListener for such case). And ZK shall run faster since that avoid the thread switching overhead.

Add following line in WEB-INF/zk.xml and it will disable ZK's event thread mechanism (but it will also disable the Modal window mechanism since Modal window is based on event thread mechanism) :

<system-config>
...
<disable-event-thread/>
...
</system-config>

Linoux
Apr 3rd, 2008, 06:51 AM
Hi Roninken,

I wonder if you had solved your problem about failing session scope bean failing to be created...

I know have the same problem, using ZK and Spring... I try adding the listener, the filter, both or them, and nothing worked :(
I try to add the "ThreadLocal" preference in ZK configuration but it didn't worked either...

Please if you succeeded in creating session scoped bean, tell me how, this is running me mad...

(My english is not too good either, sorry...)

--
Celine

Linoux
Apr 3rd, 2008, 07:33 AM
Ok, I solved that... I hadn't specified "<aop:scoped-proxy/>" in the definition of the bean...

BTW, do you know what exactly this mean ?

Regards,

--
Celine