应项目要求使用J2SE 集成 spring ,在应用JDBCTemplate进行Dao操作时,出现如下异常Exception in thread "main" java.lang.ExceptionInInitializerError at hk.egame.test.Test.main(Test.java:10)Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testDao' defined in file [F:\workspace\pay\applicationContext-bean.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1336) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381) at org.springframework.context.support.FileSystemXmlApplicationContext.(FileSystemXmlApplicationContext.java:140) at org.springframework.context.support.FileSystemXmlApplicationContext.(FileSystemXmlApplicationContext.java:84) at hk.egame.frame.util.ContextUtil.(ContextUtil.java:14) ... 1 moreCaused by: java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required at org.springframework.jdbc.core.support.JdbcDaoSupport.checkDaoConfig(JdbcDaoSupport.java:109) at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333) ... 16 more上代码(只贴上相关类,方便阅读)DaoBase.javapublic class DaoBase extends JdbcDaoSupport{ }DaoImpl.javapublic class DaoImpl extends DaoBase implements DaoInter{ @Override public void delete(User t) {...} @Override public void deleteById(int id) {...}}****** 配置文件 ******......
出错后,第一感觉是配置应该是没问题的,基类有做dataSource注入配置,查资料也未果,后无意在testDao中也注入dataSource,运行正常,经查资料,在子类Bean中也需设置父类属性,也可以修改或者覆盖父类的属性值修改后配置