2 cai772088996 cai772088996 于 2016.05.02 17:36 提问

Spring配置文件报错org.springframework.beans.factory.BeanDefinitionStoreException

总共有三个相关联的配置文件,其中dataSource.properties是连接数据库,database.xml是数据库配置,applicationContext.xml再来引用了它们

图片说明

图片说明

图片说明

报错如下:

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [database.xml]: Could not resolve placeholder 'dataSource.driverClassName' in string value "${dataSource.driverClassName}"
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:220)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:84)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:669)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

2个回答

jhfsdfs
jhfsdfs   2016.05.02 17:47
已采纳

你在property文件里怎么配置的呢?

cai772088996
cai772088996 好的,谢谢,反正第一个异常没了,也是进步
一年多之前 回复
jhfsdfs
jhfsdfs 这是hibernate的配置问题,我不太懂,你自己百度下看看
一年多之前 回复
cai772088996
cai772088996 但是又出新异常了,org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [database.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cache/CacheProvider,您知道是什么原因吗
一年多之前 回复
cai772088996
cai772088996 回复machineShunMing: 这个异常解决了,第一个${jdbc.driverClassName}改成${jdbc.driver}就好了
一年多之前 回复
jhfsdfs
jhfsdfs ${jdbc.username}这样,还有问题我就不知道了
一年多之前 回复
cai772088996
cai772088996 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean>
一年多之前 回复
cai772088996
cai772088996 改成这样嘛?还是一样的报错
一年多之前 回复
cai772088996
cai772088996 改成这样嘛?还是一样的报错
一年多之前 回复
jhfsdfs
jhfsdfs 所以啊,你应该是jdbc.xx而不是datasource
一年多之前 回复
cai772088996
cai772088996 jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql:///sshtest jdbc.username=root jdbc.password=cailikun
一年多之前 回复
CSDNXIAOD
CSDNXIAOD   2016.05.02 17:41

org.springframework.beans.factory.BeanDefinitionStoreException
org.springframework.beans.factory.BeanDefinitionStoreException
org.springframework.beans.factory.BeanDefinitionStoreException
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!