-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all,
I've followed the example stated below
http://books.zkoss.org/wiki/ZK_Spring_Essentials/Working_with_ZK_Spring/Working_with_ZK_Spring_Core/Inject_ZK_Components_in_Spring_Beans
but keep getting the following errors during initialization
SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lineChart' defined in BeanDefinition defined in class path resource [org/zkoss/spring/beans/zkcomponents/ZKComponentBeanMethods.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class org.zkoss.zul.Chart]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.NullPointerException-->null at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class org.zkoss.zul.Chart]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.NullPointerException-->null at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:206) at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:112) at org.springframework.aop.scope.ScopedProxyFactoryBean.setBeanFactory(ScopedProxyFactoryBean.java:109) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1439) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1408) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ... 19 more Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.NullPointerException-->null at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:235) at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:220) at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:216) at net.sf.cglib.proxy.Enhancer.createUsingReflection(Enhancer.java:643) at net.sf.cglib.proxy.Enhancer.firstInstance(Enhancer.java:538) at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:231) at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285) at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:200) ... 24 more
Here's both my zul and composer file
linegraph.zul =========== <?xml version="1.0" encoding="UTF-8"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <window id="barWindow" border="normal" apply="${lineGraphComposer}"> <chart id="lineChart" height="360px" threeD="false" paneColor="#FFFFFF" /> </window> LineGraphComposer.java ===================== package com.ts.bh.ui; import java.util.List; import java.util.Random; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.zkoss.spring.util.GenericSpringComposer; import org.zkoss.zk.ui.Component; import org.zkoss.zul.CategoryModel; import org.zkoss.zul.Chart; import org.zkoss.zul.SimpleCategoryModel; import com.ts.bh.ui.graph.LineGraphEngine; import com.ts.bh.business.services.ConnectionsController; import com.ts.bh.model.DataSet; @org.springframework.stereotype.Component("lineGraphComposer") @Scope("desktop") public class LineGraphComposer extends GenericSpringComposer { @Autowired private ConnectionsController connectionsController; @Autowired private Chart lineChart; @Override public void doAfterCompose(Component comp) throws Exception { List<DataSet> dataSetList = connectionsController.returnDataSet("BIGPOND", null, null, null, null); lineChart.setTitle("Simple Bar Chart"); lineChart.setType(Chart.BAR); lineChart.setModel(setModel(dataSetList)); lineChart.setXAxis("Status"); lineChart.setEngine(new LineGraphEngine()); } private CategoryModel setModel(List<DataSet> dataset) { CategoryModel model = new SimpleCategoryModel(); Random randomgen = new Random(); int val = randomgen.nextInt(3) + 1; // ACT model.setValue("ACT", "adsl", Integer.valueOf(val)); val = randomgen.nextInt(5) + 1; model.setValue("ACT", "cable", Integer.valueOf(val)); val = randomgen.nextInt(5) + 1; model.setValue("ACT", "dial", Integer.valueOf(val)); val = randomgen.nextInt(5) + 1; model.setValue("ACT", "sat2", Integer.valueOf(val)); // NSW val = randomgen.nextInt(5) + 1; model.setValue("NSW", "adsl", Integer.valueOf(val)); val = randomgen.nextInt(5) + 1; model.setValue("NSW", "cable", Integer.valueOf(val)); val = randomgen.nextInt(5) + 1; model.setValue("NSW", "dial", Integer.valueOf(val)); val = randomgen.nextInt(5) + 1; model.setValue("NSW", "sat2", Integer.valueOf(val)); // VIC val = randomgen.nextInt(5) + 1; model.setValue("VIC", "adsl", Integer.valueOf(val)); val = randomgen.nextInt(5) + 1; model.setValue("VIC", "cable", Integer.valueOf(val)); val = randomgen.nextInt(5) + 1; model.setValue("VIC", "dial", Integer.valueOf(val)); val = randomgen.nextInt(5) + 1; model.setValue("VIC", "sat2", Integer.valueOf(val)); return model; } }
Could someone please shed some light as how to make the autowiring works?
Also if I remove the @Autowire annotation, the app gets deployed but the line graph shows up blank.
Thanks.
Cheers,
Virginia
Hi,
It might be a bug. According to exception, CGLIB can't automatically generate a subclass for Chart, so autowiring fails.
I suggest you using GenericForwardComposer, it can achieve the same purpose.
Asked: 2011-11-16 11:49:42 +0800
Seen: 670 times
Last updated: Nov 30 '11