-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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.
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.
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
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
Asked: 2006-07-13 09:42:37 +0800
Seen: 286 times
Last updated: Jul 14 '06