-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Tried the following...
public class SessionInitImpl implements SessionInit {
private MyService myService = (MyService) SpringUtil.getBean("myService");
Got error...
"SpringUtil can be called only under ZK environment"
How to access Spring Bean within SessionInit Implementation?
Thanks!
I think sessionInit is too early for ZK's SpringUtils to do it's work, at that moment, ZK hasn't make that servlet thread been managed by ZK yet.
if you want to get Spring bean in sessionInit, you can get it through:
private static ApplicationContext getApplicationContext(Session zkSession){ return WebApplicationContextUtils.getRequiredWebApplicationContext( (ServletContext)zkSession.getWebApp().getNativeContext()); } public static Object getBean(String name) { Object o = null; try { if(getApplicationContext().containsBean(name)) { o = getApplicationContext().getBean(name); } } catch (NoSuchBeanDefinitionException ex) { // ignore } return o; }
add this two methods into your sessionInit and use them.
Asked: 2010-11-27 17:41:55 +0800
Seen: 460 times
Last updated: Nov 28 '10