Im trying to setup a Spring MVC web app using Hibernate ORM. Im using JBOSS AS.
There is a problem when Im trying to define a datasource bean:
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
When I run the app and access it via browser, it throws an exception -
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/servletCtx.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource from [Module "deployment.untitled1.war:main" from Service Module Loader]
I've read somewhere that this datasource approach is old and deprecated. Is it true? What else would you suggest?
Thanks for hints and help.
java.lang.ClassNotFoundException
means the required JAR file that contains org.apache.commons.dbcp.BasicDataSource
is not available in classpath, just add it to fix the issue.
Instead of configuring it as a data-source use JNDI connection.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.