-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello All!
I'm trying to run same code as:
ZK Spring Essentials/Working with ZK Spring/Working with ZK Spring Core/Inject ZK Components in Spring Beans
but getting error:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.zkoss.zul.Textbox] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency
and i don't have package "org.zkoss.spring.beans", is it constructed at runtime?
can anybody help me?
my code:
zul:
<?xml version="1.0" encoding="UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window title="Autowire ZK Components Example2" border="normal" height="100px"
width="400px" apply="${greetingCtrl}">
<label value="Name:"></label>
<textbox id="name" />
<button id="greetBtn" label="Greet!" />
</window>
java:
package temp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.zkoss.spring.context.annotation.EventHandler;
import org.zkoss.spring.util.GenericSpringComposer;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Textbox;
@org.springframework.stereotype.Component("greetingCtrl")
@Scope("desktop")
public class zkess1 extends GenericSpringComposer {
@Autowired
public Textbox name;
// @Autowired
// private Button greetBtn;
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
}
@EventHandler("greetBtn.onClick")
public void showGreeting(Event evt) throws WrongValueException, InterruptedException {
Messagebox.show("Hello " + name.getValue() + "!");
}
}
web.xml
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<description><![CDATA[TempForms APP]]></description>
<display-name>TempForms</display-name>
<!-- SPRING -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/applicationContext.xml</param-value>
</context-param>
<!-- ZK Spring-->
<servlet>
<servlet-name>zkLoader</servlet-name>
<servlet-class>
org.zkoss.zk.ui.http.DHtmlLayoutServlet
</servlet-class>
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>auEngine</servlet-name>
<servlet-class>
org.zkoss.zk.au.http.DHtmlUpdateServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:zksp="http://www.zkoss.org/2008/zkspring/core"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.zkoss.org/2008/zkspring/core http://www.zkoss.org/2008/zkspring/core/zkspring-core.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:component-scan base-package="temp,org.zkoss.spring.bean,org.zkoss.zkspringessentials.controller,org.zkoss.spring.beans.zkcomponents"></context:component-scan>
<zksp:zk-config/>
</beans>
Hi Vovka,
>> i don't have package "org.zkoss.spring.beans", is it constructed at runtime?
Yes
And you have missed the very first step in the configuration i.e. to add
<listener> <listener-class>org.zkoss.spring.web.context.CoreContextListener</listener-class> </listener>
Huge Thanks!
it works, at last.
Amazing! i have looked and checked code hundred times.
But not recognized difference "org.zkoss.spring.web.context.CoreContextListener" vs "org.springframework.web.context.ContextLoaderListener"
Asked: 2011-05-24 03:54:55 +0800
Seen: 1,127 times
Last updated: May 25 '11