Spring 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <bean id="sessionFactory" 
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>


<bean id="objectDao" class="com.zh.epai.Dao.Item.ObjectDaoItem">
<property name="sessionFactory" ref="sessionFactory" />
<property name="objectDao" ref="objectDao"></property>
</bean>

<bean id="objectBiz" class="com.zh.epai.Biz.Impl.ObjectBizImpl">
<property name="objectDao" ref="objectDao"></property>
</bean>

<bean id="textDao" class="text.textObjectDao">
<property name="objectDao" ref="objectDao"></property>
</bean>

<bean id="wori" class="com.zh.epai.Biz.Impl.ObjectBizImpl">
<property name="objectDao" ref="objectDao"></property>
</bean>
</beans>
//后台代码
package com.zh.epai.Biz.Impl;import com.zh.epai.Biz.ObjectBiz;
import com.zh.epai.Dao.ObjectDao;
import com.zh.epai.entity.TUser;public class ObjectBizImpl implements ObjectBiz {

ObjectDao objectDao;
public ObjectDao getObjectDao() {
return objectDao;
} public void setObjectDao(ObjectDao objectDao) {
this.objectDao = objectDao;
} public int addObject(Object item) {
System.out.println(objectDao);
return objectDao.addObject(item);
}
}
问题:获取不到objectDao   objectDao为null在线求救高手

解决方案 »

  1.   

    指定其autowire属性为byName:<bean id="objectBiz" class="com.zh.epai.Biz.Impl.ObjectBizImpl" autowire="byName" /> 
      

  2.   

    <bean id="objectDao" class="com.zh.epai.Dao.Item.ObjectDaoItem"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
    <property name="objectDao" ref="objectDao"> </property> 
    </bean> 
    是不是上面的有问题
      

  3.   

    <bean id="objectDao" class="com.zh.epai.Dao.Item.ObjectDaoItem"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
    <property name="objectDao" ref="objectDao"> </property> 
    </bean> 
    你把自己注入到自己里面去,相当于自己把自抱起来.这样能行?
      

  4.   

    去我博客看看,里面有你想要的东西:
        http://blog.csdn.net/wumingzu/archive/2009/05/07/4157177.aspx
      
      

  5.   

    去我博客看看,里面有你想要的东西: 
    http://blog.csdn.net/wumingzu/archive/2009/05/07/4157177.aspx