0

Spring Bean inside SessionInit implementation

asked 2010-11-27 17:41:55 +0800

eptx gravatar image eptx
130 3

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!

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2010-11-28 02:15:39 +0800

iantsai gravatar image iantsai
2755 1

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.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-11-27 17:41:55 +0800

Seen: 459 times

Last updated: Nov 28 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More