Spring居然不给我注入dao对象,怎么办?

来源:百度知道 编辑:UC知道 时间:2024/05/27 04:27:15
使用Spring管理hibernate,在Action中使用servlet(来自DAO封装)查询数据库,在启动时没问题,但是单击按钮激活Action时出现
Servlet.service() for servlet default threw exception
java.lang.NullPointerException
at action.StudentAction.execute(StudentAction.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
。。。
在dao里getHibernateTemplate() 得到的是null 其他一切都正常

说明配置文件配的有问题,把applicationContext.xml中对于Action的配置检查一下,还有struts-config.xml中的插件配置也是,应该是DAO没有注入到Action中造成的。

可以加入log4j.properties检查启动是否报错。

" at action.StudentAction.execute(StudentAction.java:40)"说明是配置问题。struts.xml 中action中的class属性应该写成applicationContext.xml中对应bean的id。

这说明你HIBERNATE的配置都没有配好。applicationcontext.xml检查hibernatetemplate的配置