0

Access Spring ApplicationContext in a ZK Java Composer

asked 2010-11-16 20:30:25 +0800

olivier gravatar image olivier
36

I would like to access a service class I have defined and registered it in my beans.xml file.
However, I do not know how to retrieve my instance without forcing reading the XML file. I would just like to retrieve the application context instance and get my service bean. Is it possible?

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2010-11-16 22:46:23 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

http://www.zkoss.org/javadoc/5.0.4/zk/org/zkoss/zkplus/spring/SpringUtil.html

link publish delete flag offensive edit

answered 2010-11-17 13:05:37 +0800

olivier gravatar image olivier
36

Thanks, this works great!

link publish delete flag offensive edit

answered 2010-11-17 15:02:57 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

I don't know the paradigm that you're using, but you can easily have your composers instantiated by Spring when needed and have them resolved by

    <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
...
    <window id="xxxx" ... apply="${myController}" .... >
        ....
    </window>

this will cause Spring to lookup a bean with id = "myController" in its context. If the bean is defined like this:

    <bean id="myController" class="com.my.package.controllers.MyController" scope="prototype">
        <property name="property1" ref="beanRef1" />
        <property name="property2" ref="beanRef2" />
        <property name="property2" ref="beanRef2" />
    </bean>

then you have a fully "Springified" implementation. This assumes you've started the Spring context with org.springframework.web.context.ContextLoaderListener in your web.xml.

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-16 20:30:25 +0800

Seen: 617 times

Last updated: Nov 17 '10

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