0

How to reach Spring's beanfactory with ZK?

asked 2006-07-13 09:42:37 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3820138

By: nobody

Hi,

I tried to integrate ZK with Spring and therefore used the examples from the small talks. I included Spring's ContextLoaderListener in web.xml:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-
class>
</listener>

This works and my beans are found as seen in Tomcat's console:

org.springframework.web.context.support.XmlWebApplicationContext:92 - Bean factory for application context [Root WebApplicationContext]:
org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [userDao,dataSource,sessionFactory,hibernateTemplate,userManager,userService];
root of BeanFactory hierarchy

Now I implemented the ServiceLocator, which does the following to the the
context:

static {
ctx = new ClassPathXmlApplicationContext("spring-hibernate.xml");
}

This doesn't work for me because the spring-*.xml files are not within the class path (/WebRoot/WEB-INF) and I'm not sure how to change this. So I changed it to "**/spring-hibernate.xml" and the file seems to be found. But then I get the following:
NoSuchBeanDefinitionException: No bean named 'userManager' is defined

What worked for me in the old myfaces implementation was this:
ServletContext context
= (ServletContext)FacesContext.getCurrentInstance().getExternalContext().getCont
ext();
this.appContext
= WebApplicationContextUtils.getRequiredWebApplicationContext(context);

But I don't know how to do this with ZK because I don't get a valid ServletContext.
After that, getting the beanfactory should not be a problem.

Does anyone have a hint for me?

Regards,
Oliver.

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2006-07-13 10:03:32 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3820162

By: nobody

Ok, after trying for hours and posting this, I found a way. I removed the whole ApplicationContext stuff and changed the functions in the ServiceLocator to get a service to this:

public static UserManager getUserManager() {
return (UserManager) new
DelegatingVariableResolver().getVariable("userManager");
}

I hope this is a valid way to do it.

Regards,
Oliver.

link publish delete flag offensive edit

answered 2006-07-14 17:26:13 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3822263

By: henrichen

To get a valid ServletContext, please see this API.

http://zk1.sourceforge.net/javadoc/2.1.0/zk/com/potix/zk/ui/WebApp.html#getNativ
eContext()

/henri

link publish delete flag offensive edit

answered 2006-07-14 17:37:14 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3822277

By: henrichen

Yes, this is a valid way. DelegatingVariableResolver is a Spring bean variable resolver and our solution to seamlessly integrate ZK with Spring.

You can also get the Spring's ApplicationContext by this utility class.

By using <?variable-resolver class="..."?> directive, you can even access the Spring's bean object inside zscript directly.(Please see developer's guide on how to use the directive)

We are going to post a smalltalk detailing on how to use this resolver to access Spring's bean objects.

/henri

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: 2006-07-13 09:42:37 +0800

Seen: 286 times

Last updated: Jul 14 '06

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