今天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没问题呀,大家能看出哪里有问题吗SpringJava

解决方案 »

  1.   


    不好意思,有个方法粘贴错:getorderDAO(),应该是:getOrderDAO()的,还是会报错的,
      

  2.   

    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.   

    private OrderDAOItf orderDAO;
    OrderDAOItf 这个类型。。Itf是打错了么?
      

  4.   


    没错呀,这是个dao的接口,为什么你会认为会可能是打错了呢,大神求解
      

  5.   

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

  6.   

    http://blog.sina.com.cn/s/blog_6fd8a5870100uq5f.html
    应该是不规范导致的吧,,我没有写过DAO全部大写
      

  7.   


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

  8.   


    这是因为OrderDAO实现接口OrderDAOItf ,然后我service类那里写接口是没错的吧
    对,你这样用没问题。。
    要不你属性orderDAO换个名字,都小写,然后自动生成getter和setter,在重新部署下工程试试?
      

  9.   

    我猜是"wteam.dao.ordManageDAO.OrderDAO"类没有实现OrderDAOltf接口
      

  10.   

    另外bean定义时,建议使用id:<bean id="orderDetailsDAO"...
      

  11.   

    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方法了。