当前位置:编程学习 > JAVA >>

spring报错

今天spring报错呀,请看以下报错,

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext_service.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'orderDAO' of bean class [wteam.service.ordManageService.OrderDetailsService]: Bean property 'orderDAO' 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.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


这是我的xml文件的配置:
<bean name="orderDAO" class="wteam.dao.ordManageDAO.OrderDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean name="orderDetailsDAO" class="wteam.dao.ordManageDAO.OrderDetailsDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean name="orderDetailsService" class="wteam.service.ordManageService.OrderDetailsService">
<property name="orderDetailsDAO" ref="orderDetailsDAO"/>
<property name="orderDAO" ref="orderDAO"/>
</bean>


java代码那部分:

private OrderDAOItf orderDAO;

public OrderDAOItf getorderDAO() {
return orderDAO;
}

public void setOrderDAO(OrderDAOItf orderDAO) {
this.orderDAO = orderDAO;
}

感觉我的set和get没问题呀,大家能看出哪里有问题吗 Spring Java --------------------编程问答--------------------
引用 楼主 GanJunhong 的回复:
今天spring报错呀,请看以下报错,

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext_service.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'orderDAO' of bean class [wteam.service.ordManageService.OrderDetailsService]: Bean property 'orderDAO' 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.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


这是我的xml文件的配置:
<bean name="orderDAO" class="wteam.dao.ordManageDAO.OrderDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean name="orderDetailsDAO" class="wteam.dao.ordManageDAO.OrderDetailsDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean name="orderDetailsService" class="wteam.service.ordManageService.OrderDetailsService">
<property name="orderDetailsDAO" ref="orderDetailsDAO"/>
<property name="orderDAO" ref="orderDAO"/>
</bean>


java代码那部分:

private OrderDAOItf orderDAO;

public OrderDAOItf getorderDAO() {
return orderDAO;
}

public void setOrderDAO(OrderDAOItf orderDAO) {
this.orderDAO = orderDAO;
}

感觉我的set和get没问题呀,大家能看出哪里有问题吗


不好意思,有个方法粘贴错:getorderDAO(),应该是:getOrderDAO()的,还是会报错的, --------------------编程问答-------------------- Bean property 'orderDAO' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

大概是你的set和get有问题呀,,类型不匹配 --------------------编程问答--------------------
引用 2 楼 zhctj159 的回复:
Bean property 'orderDAO' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

大概是你的set和get有问题呀,,类型不匹配


我也知道他报错的说那里有问题,可是看起来没问题呀,不知道是怎么错的 --------------------编程问答--------------------
引用 3 楼 GanJunhong 的回复:
Quote: 引用 2 楼 zhctj159 的回复:

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

大概是你的set和get有问题呀,,类型不匹配


我也知道他报错的说那里有问题,可是看起来没问题呀,不知道是怎么错的
类型不匹配,都说到这里了 --------------------编程问答-------------------- private OrderDAOItf orderDAO;
OrderDAOItf 这个类型。。Itf是打错了么? --------------------编程问答--------------------
引用 5 楼 oh_Maxy 的回复:
private OrderDAOItf orderDAO;
OrderDAOItf 这个类型。。Itf是打错了么?


没错呀,这是个dao的接口,为什么你会认为会可能是打错了呢,大神求解 --------------------编程问答-------------------- 可是你配置文件里这样定义的:<bean name="orderDAO" class="wteam.dao.ordManageDAO.OrderDAO">
OrderDAO和OrderDAOItf 不一样吧? --------------------编程问答-------------------- http://blog.sina.com.cn/s/blog_6fd8a5870100uq5f.html
应该是不规范导致的吧,,我没有写过DAO全部大写 --------------------编程问答--------------------
引用 7 楼 oh_Maxy 的回复:
可是你配置文件里这样定义的:<bean name="orderDAO" class="wteam.dao.ordManageDAO.OrderDAO">
OrderDAO和OrderDAOItf 不一样吧?


这是因为OrderDAO实现接口OrderDAOItf ,然后我service类那里写接口是没错的吧 --------------------编程问答--------------------
引用 9 楼 GanJunhong 的回复:
Quote: 引用 7 楼 oh_Maxy 的回复:

可是你配置文件里这样定义的:<bean name="orderDAO" class="wteam.dao.ordManageDAO.OrderDAO">
OrderDAO和OrderDAOItf 不一样吧?


这是因为OrderDAO实现接口OrderDAOItf ,然后我service类那里写接口是没错的吧

对,你这样用没问题。。
要不你属性orderDAO换个名字,都小写,然后自动生成getter和setter,在重新部署下工程试试? --------------------编程问答-------------------- 估计是变量名的问题。代码好像没看出来有什么问题。现在也不方便帮你测试下…… --------------------编程问答-------------------- 我猜是"wteam.dao.ordManageDAO.OrderDAO"类没有实现OrderDAOltf接口 --------------------编程问答-------------------- 另外bean定义时,建议使用id:<bean id="orderDetailsDAO"... --------------------编程问答-------------------- set get注入的依据不是你是否定义了这个变量,而看你是否有这个变量的set和get方法。
private OrderDAOItf orderDAO;

public OrderDAOItf getorderDAO() {
return orderDAO;
}

public void setOrderDAO(OrderDAOItf orderDAO) {
this.orderDAO = orderDAO;
}

<bean name="orderDetailsService" class="wteam.service.ordManageService.OrderDetailsService">
<property name="orderDetailsDAO" ref="orderDetailsDAO"/>
<property name="orderDAO" ref="orderDAO"/>
</bean>

你bean里这样定义,他默认会去找setOrderDAO和getOrderDAO

找不到,就说你没有为这个属性提供set和get方法了。
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,