Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'dataSource' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1141)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1177)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:758)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:422)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.ClassPathXmlApplicationContext.
at org.springframework.context.support.ClassPathXmlApplicationContext.
at org.database.shopCarDao.main(shopCarDao.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:211)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:385)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1138)
明顯的是 org.springframework.beans.factory.CannotLoadBeanClassException
就是 Spring 在加載 bean 時發生錯誤而無法加載
後面也補上一句 Cannot find class [org.apache.commons.dbcp.BasicDataSource]
看來這是出在配置檔的,如下紅色標示處所示
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/ >
<property name="url" value="jdbc:mysql://localhost:3306/shopcar"/ >
<property name="username" value="root"/ >
<property name="password" value="1111"/>
</bean>
所以是缺少了某些 library,而如果你有下載 Spring 的話
可以在目錄下的 lib 裡找到ㄧ個目錄 jakarta-commons
在打下有很多 Apache 基金會所發布的開源套件,找到 commons-dbcp.jar
並把它匯入到你目前專案中或是加至 Eclipse 的環境下即可了
關於更多 DBCP 可以到 http://commons.apache.org/dbcp/ 查看唷
如果如上一篇以一個 Java WEB 專案來配置 DBCP 連接池的話
那可能還需要多加入 commons-pool.jar 喔~
沒有留言:
張貼留言