问题的原因:
在web项目中搭建SSM框架,启动Tomcat时出现错误信息
有配置文件:applicationContext-mybatis.xml (Spring配置)
spring-servlet.xml(SpringMVC配置)
mybatis-config.xml(Mybatis配置)
log4j.properties
jdbc.properties
截取部分错误信息片段:
- (1912 ms) - [ERROR] 2016-08-30 22:48:02,924 org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dateSource' defined in file [D:Program Filesapache-tomcat-8.0.33apache-tomcat-8.0.33webappsspringmvcproject-testWEB-INFclassesapplicationContext-mybatis.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driver' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'driver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1423)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
尝试过的办法有:
更换数据源的配置
更换jdbc.properties
重写applicationContext-mybatis.xml
清空Tomcat所在目录下的work文件夹与webapps文件夹
更换过jar包
但错误依旧。。。。。
最后,将Spring配置文件applicationContext-mybatis.xml的名称
改为 application-mybatis.xml
错误消失!!!
错误原因:
初步认为是其他web项目下有同名的Spring配置文件applicationContext-mybatis.xml,
在启动Tomcat时造成混淆。
考虑到之前清空过Tomcat目录下的work文件夹与webapps文件夹,
所以,暂时推断为Tomcat缓存中的残余。
由于我也在学习Java的时期中,所以还需要研究,关于Tomcat缓存并不了解,
如果有牛人路过,希望留下指点,感激不尽。