<ref local="testDAO">是在本XML配置文件中寻找一个id为testDAO的bean你必须要配置

解决方案 »

  1.   

    testDAO这个bean已经配好了,应该不是这个问题。
      <bean id="testService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager"><ref local="myTransactionManager"/></property>
    <property name="target"><ref local="testTarget"/></property>
    <property name="transactionAttributes">
         <props>
              <prop key="create*">PROPAGATION_REQUIRED,-TestException</prop>
         </props>
    </property>
    </bean>  <!-- OrderTarget primary business object implementation -->
       <bean id="testTarget" class="demo.service.dao.TestServiceSpring">
    <property name="testDAO"><ref local="testDAO"/></property>
    </bean>  <!-- DAO object: Hibernate implementation -->
    <bean id="testDAO" class="demo.dao.hibernate.TestDao">
    <property name="sessionFactory"><ref local="mySessionFactory"/></property>
    </bean>
      

  2.   

    报错:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testService' defined in resource [/WEB-INF/spring.bean.xml] of ServletContext: Can't resolve reference to bean 'testTarget' while setting property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testTarget' defined in resource [/WEB-INF/spring.bean.xml] of ServletContext: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'testDAO' of bean class [demo.service.dao.TestServiceSpring]: Property 'testDAO' is not writableorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testTarget' defined in resource [/WEB-INF/spring.bean.xml] of ServletContext: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'testDAO' of bean class [demo.service.dao.TestServiceSpring]: Property 'testDAO' is not writableorg.springframework.beans.NotWritablePropertyException: Invalid property 'testDAO' of bean class [demo.service.dao.TestServiceSpring]: Property 'testDAO' is not writable