<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="hibernateProperties"> 
            <props> 
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> 
                <prop key="show_sql">true</prop> 
            </props> 
        </property> 
        <property name="mappingResources"> 
            <list> 
               <value>com/ecp/etl/etl.hbm.xml</value> 
            </list> 
        </property> 
        
    </bean>
   
    
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    
    <bean id="etldao" class="com.ecp.etl.dao.impl.EtlDaoImp">
     <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!--
    <bean id="bossAdapter" class="com.ecp.etl.service.impl.BossServiceImpl"></bean>
    -->
    <bean id="writeLogtaskService" class="com.ecp.etl.service.MyTask">
     <property name="etldao" ref="etldao"></property>
     <!-- 
     <property name="bossService" ref="bossAdapter" />
        <property name="run" value="true" />
        -->
        <property name="sendBillList">
            <list>
                <value>13777367287</value>
                <value>13588713204</value>
                <value>15825515025</value>
            </list>
        </property>
    </bean>public void setBossService(IBossService bossService) {
this.bossService = bossService;
}


public void setEtldao(EtlDao etldao) {
this.etldao = etldao;
}

public void setSendBillList(List<String> sendBillList) {
this.sendBillList = sendBillList;
}

public MyTask(){
sndMessage = new SendSMS();
sndMessage.start();
}

public void run() {
Date currentTime = new Date();//当前时间
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

List list = etldao.findResult();
                 此处 java.lang.NullPointerException,为什么dtldao无法注入?

解决方案 »

  1.   

     java.lang.NullPointerException,你怎么就确定是dtldao无法注入,顺便进来学习学习
      

  2.   

    没有详细的代码,猜测的一种可能性:
    构造函数MyTask()执行过程中,在spring注入etldao之前,run()就方法执行了。MyTask构造方法里面是启动了一个新线程对象是么?sndMessage.start();会出发run()方法执行?
      

  3.   

    估计new出来的,没有set,当然是空了
    要getbean才行
      

  4.   

    spring的注入获得bean的方式有很多这招应该可以ApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(session.getServletContext());
    Dao dao = (Dao)ctx.getBean(id名);