8

I'm trying to create a web application using maven, tomcat and hibernate. Now I'm getting a cannot find class for org.appache.commons.dbcp.basicdatasource for bean with name datasource... exception.

Without the hibernate aspects it works fine, but if I add

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
    <property name="username" value="temp"/>
    <property name="password" value="temp"/>
</bean> 

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.hbm2ddl.auto">create</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
    <property name="mappingResources">
        <list>
        </list>
    </property>
</bean> 

to my applicationContext then I get the error.

What I did was:

  • add org.hibernate to my pom
  • put ojdbc16.jar in my tomcat bin folder
  • add the above snippet to my applicationContext.xml

I use a bat file to compile my project (using maven), copy it to my tomcat webapp folder and to start the server.

Any input on what I'm doing wrong is welcome.

1 Answer 1

17

You're very likely missing the dependency for Commons DBCP:

<dependency>
  <groupId>commons-dbcp</groupId>
  <artifactId>commons-dbcp</artifactId>
  <version>1.4</version>
</dependency>
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for the response. I added that to my pom but I get: Missing artifact commons-dbcp:commons-dbcp:jar:1.4:compile I'm not that familiar yet with maven. I tried putting the commons-dbcp on scope: compile but that didn't help.
@Joe That's strange. I double checked and this artifact is definitely in the central repository. Do you run maven "online"? Who is complaining about the missing artifact exactly?
My compiler.I added: <repository> <id>repo1</id> <name>repo1</name> <url>repo1.maven.org/maven2/</url> </repository> And it doesn't complain anymore, so I guess the repository lacked that jar.
very odd. This repository is added by default

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.