up2do
2017-05-05 07:10
采纳率: 100%
浏览 1.5k
已采纳

job调用mybatis dao层方法时报空指针错误

代码
public void addYzToken(){

    String refreshToken="";
    try {
        refreshToken=tokenDao.getLastYzToken().getRefreshToken();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println(refreshToken+"---");
    }

    异常信息:
    java.lang.NullPointerException

at com.sinowel.job.RefreshTokenTask.addYzToken(RefreshTokenTask.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

spring 配置
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="configLocation" value="classpath:db/sqlMapConfig.xml" />
    <property name="mapperLocations" value="classpath:mybatis/com/sinowel/data/**/*.xml" />
    <property name="dataSource" ref="dataSource" />
</bean>
<!--MyBatis SqlSessionTemplate注入 -->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
    <!-- <property name="sqlSessionFactory" ref="sqlSessionFactory" /> -->
    <constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg>
</bean>

<!--自定义commonDao注入 -->
<bean id="dao" class="com.sinowel.core.dao.ibatis.IbatisDao">
    <property name="sqlSessionTemplate" ref="sqlSessionTemplate" />
</bean>

求大神指点
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 毕小宝 2017-05-05 08:34
    已采纳

    首先,你是怎么初始化这个DAO对象的,Spring托管的呢,还是手动创建的对象;
    其次,如果是Spring自动注入的,这个类上面有没有注解属性呢,扫描包路径有没有包含这个类。

    评论
    解决 无用
    打赏 举报
  • 查看更多回答(2条)

相关推荐 更多相似问题