您的位置:首页 > 编程语言 > Java开发

s2sh框架中spring注入错误-no getter

2010-05-28 11:00 309 查看
错误的信息如下:

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataShareServiceImpl' defined in file [C:/Documents and Settings/Administrator/workspace/.metadata/.plugins/com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/GeoGlobeAdmin/WEB-INF/classes/spring/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'hibernateTemplate' of bean class [com.geoglobeportal.appservice.service.impl.DataShareService]: Bean property 'hibernateTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'hibernateTemplate' of bean class [com.geoglobeportal.appservice.service.impl.DataShareService]: Bean property 'hibernateTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
 at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:793)
 at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:648)
 at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
 at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1127)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:291)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:189)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
 at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
 at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
 at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
 at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
 at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
 at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
 at org.apache.catalina.core.StandardService.start(StandardService.java:516)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

 

解决此类问题的关键在于找到关键的错误语句,这次关键的错误语句是:

Bean property 'hibernateTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

 

在这个错误中我们可以发现'hibernateTemplate'没有getter,是什么原因造成没有getter的呢?

hibernateTemplate'是依赖于sessionFactory的

其实前面的 Error creating bean with name 'dataShareServiceImpl' defined in file中我们可以发现dataShareServiceImpl是错误的来源,说白了就是'dataShareServiceImpl'中没有setSessionFactory()

解决方法:

可以让 'dataShareServiceImpl' extends JdbcDaoSupport
或者 'dataShareServiceImpl' extends HibernateDaoSupport

在以上两个继承类中都实现了getter和setter方法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐