oracle hibernate + maven dependenciesm dbcp.basicdatasource 异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2669951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:26:48  来源:igfitidea点击:

oracle hibernate + maven dependenciesm dbcp.basicdatasource exception

oraclehibernatespringtomcatmaven-2

提问by Mike

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.

我正在尝试使用 maven、tomcat 和 hibernate 创建一个 web 应用程序。现在我得到了一个无法找到 org.appache.commons.dbcp.basicdatasource 的类,用于名称为 datasource... 异常的 bean。

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.

到我的 applicationContext 然后我得到错误。

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
  • 将 org.hibernate 添加到我的 pom
  • 将 ojdbc16.jar 放在我的 tomcat bin 文件夹中
  • 将上面的代码片段添加到我的 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.

我使用 bat 文件编译我的项目(使用 maven),将其复制到我的 tomcat webapp 文件夹并启动服务器。

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

欢迎任何关于我做错了什么的意见。

回答by Pascal Thivent

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

您很可能缺少 Commons DBCP 的依赖项:

<dependency>
  <groupId>commons-dbcp</groupId>
  <artifactId>commons-dbcp</artifactId>
  <version>1.4</version>
</dependency>