org.apache.tomcat.dbcp.dbcp.SQLNestedException:无法创建类“”的 JDBC 驱动程序对于连接 URL“null”

发布于 2024-10-05 18:19:59 字数 4894 浏览 2 评论 0原文

我正在使用 spring、hybernate +jpa 开发一个基于 Web 的项目。我正在尝试使用 Atomkios 配置 JTA 事务 我的后端是mySql。我无法将应用程序设置为与 mySql 一起使用。 我的网络服务器是 tomcat 5.5。我正在尝试校准 jndi 配置的数据源..这里我的代码是

persistence.xml:

  <persistence-unit name="exhub" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:comp/env/jdbc/exampleWeb</jta-data-source>
        <mapping-file>META-INF/orm.xml</mapping-file>
   <class>com.evolvus.common.model.Talogin</class>
   <class>com.evolvus.common.model.TaUser</class>  
            ----------------- 
            -----------------  
           <properties>
            <property name="hibernate.transaction.manager_lookup_class" 
            value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>
            </ properties>     
 </persistence-unit>
</persistence>

orm.xml:

<description>Evolvus Solutions</description> 
<package>com.evolvus.common.model</package>


 <entity class="com.evolvus.common.model.TaUser" name="TaUser">
  <table name="ta_user" />
  <attributes>
   <id name="userId">
   <column name="USER_ID"/>
    <generated-value strategy="TABLE" />
   </id>
   <basic name="userName">
    <column name="USER_NAME" length="50" />
   </basic>

  </attributes>
 </entity>
  ---------------
  --------------
  ---------------

</entity-mappings>

config.xml:

 <beans: bean id="sessionFactory"   
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <beans: property name="useTransactionAwareDataSource"
   value="true" /> 
  <beans: property name="hibernateProperties">
   <beans: props>
    <beans: prop key="hibernate.dialect">${database.target}</beans:prop>
    <beans: prop key="hibernate.connection.isolation">3</beans:prop>
    <beans: prop key="hibernate.current_session_context_class">jta</beans:prop>
    <beans: prop key="hibernate.transaction.factory_class">com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory
    </beans: prop>
    <beans: prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
    </beans: prop>
    <beans: prop key="hibernate.connection.release_mode">on_close</beans: prop>
    <beans: prop key="hibernate.show_sql">false</beans: prop>
   </beans: props>
  </beans: property>
 </beans: bean>

 <beans: bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
  <beans: property name="entityManagerFactory">
   <beans: ref bean="entityManagerFactory" />
  </beans: property>
 </beans: bean>
 <beans: bean id="entityManagerFactory"
  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <beans: property name="persistenceUnitName" value="payhub" />
  <beans: property name="jpaVendorAdapter">
   <beans:bean
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <beans: property name="generateDdl" value="false" />
    <beans: property name="showSql" value="true" />
    <beans: property name="databasePlatform" value="${database.target}" />
   </beans: bean>
  </beans: property>
  <beans: property name="persistenceXmlLocation">
   <beans: value>classpath:META-INF/persistence.xml</beans:value>
  </beans: property>
 </beans: bean>
</beans: beans>

我在 tomcat 5.5

Apache Software Foundation\Tomcat 5.5\conf.xml 中配置了 jndi :

 <Resource
      name="jdbc/exampleWeb"
      type="javax.sql.DataSource"
      maxActive="4"
      maxIdle="2"
      username="root"
      maxWait="5000"
      validationQuery="SELECT=1"
      driverClassName="com.mysql.jdbc.Driver"
      password="roopt"  
      url="jdbc\:mysql\://localhost\:3306/welcomeHub"/> 

 and my application\web.xml 

 <resource-ref>
   <description>PaymentsDatabase</description>
   <res-ref-name>jdbc/exampleWeb</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref> 

我的服务器运行良好,但是当我尝试访问数据库数据时,我在 Web 浏览器中收到以下错误

org.springframework.jdbc.CannotGetJdbcConnectionException:无法获取 JDBC 连接;嵌套异常是 org.apache.tomcat.dbcp.dbcp.SQLNestedException:无法为连接 URL 'null' 创建类 '' 的 JDBC 驱动程序 org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)

帮助我

I am working on a web based project using spring ,hybernate +jpa .I am trying to configure JTA Transactions with Atomkios
my backend is mySql. I am not able to setup the application to work with mySql.
my web server is tomcat 5.5.I am trying to cal jndi configured datasource .. here my code is

persistence.xml:

  <persistence-unit name="exhub" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:comp/env/jdbc/exampleWeb</jta-data-source>
        <mapping-file>META-INF/orm.xml</mapping-file>
   <class>com.evolvus.common.model.Talogin</class>
   <class>com.evolvus.common.model.TaUser</class>  
            ----------------- 
            -----------------  
           <properties>
            <property name="hibernate.transaction.manager_lookup_class" 
            value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>
            </ properties>     
 </persistence-unit>
</persistence>

orm.xml:

<description>Evolvus Solutions</description> 
<package>com.evolvus.common.model</package>


 <entity class="com.evolvus.common.model.TaUser" name="TaUser">
  <table name="ta_user" />
  <attributes>
   <id name="userId">
   <column name="USER_ID"/>
    <generated-value strategy="TABLE" />
   </id>
   <basic name="userName">
    <column name="USER_NAME" length="50" />
   </basic>

  </attributes>
 </entity>
  ---------------
  --------------
  ---------------

</entity-mappings>

config.xml:

 <beans: bean id="sessionFactory"   
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <beans: property name="useTransactionAwareDataSource"
   value="true" /> 
  <beans: property name="hibernateProperties">
   <beans: props>
    <beans: prop key="hibernate.dialect">${database.target}</beans:prop>
    <beans: prop key="hibernate.connection.isolation">3</beans:prop>
    <beans: prop key="hibernate.current_session_context_class">jta</beans:prop>
    <beans: prop key="hibernate.transaction.factory_class">com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory
    </beans: prop>
    <beans: prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
    </beans: prop>
    <beans: prop key="hibernate.connection.release_mode">on_close</beans: prop>
    <beans: prop key="hibernate.show_sql">false</beans: prop>
   </beans: props>
  </beans: property>
 </beans: bean>

 <beans: bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
  <beans: property name="entityManagerFactory">
   <beans: ref bean="entityManagerFactory" />
  </beans: property>
 </beans: bean>
 <beans: bean id="entityManagerFactory"
  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <beans: property name="persistenceUnitName" value="payhub" />
  <beans: property name="jpaVendorAdapter">
   <beans:bean
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <beans: property name="generateDdl" value="false" />
    <beans: property name="showSql" value="true" />
    <beans: property name="databasePlatform" value="${database.target}" />
   </beans: bean>
  </beans: property>
  <beans: property name="persistenceXmlLocation">
   <beans: value>classpath:META-INF/persistence.xml</beans:value>
  </beans: property>
 </beans: bean>
</beans: beans>

and i configured jndi in tomcat 5.5

Apache Software Foundation\Tomcat 5.5\conf.xml:

 <Resource
      name="jdbc/exampleWeb"
      type="javax.sql.DataSource"
      maxActive="4"
      maxIdle="2"
      username="root"
      maxWait="5000"
      validationQuery="SELECT=1"
      driverClassName="com.mysql.jdbc.Driver"
      password="roopt"  
      url="jdbc\:mysql\://localhost\:3306/welcomeHub"/> 

 and my application\web.xml 

 <resource-ref>
   <description>PaymentsDatabase</description>
   <res-ref-name>jdbc/exampleWeb</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref> 

My server is staring fine but when i trying to access db data i am getting the following error in my web browser

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)

Help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦归所梦 2024-10-12 18:19:59

我认为您的应用程序没有找到 mysql 连接器 jar 文件或者您的 url 配置错误。

尝试以下方法

  1. 将 mysql 连接器 jar 文件放在 tomcat/common/lib 下,以便在 webapp 类之前获取它。
  2. 更改您的 context.xml 以包含如下资源。

    <前><代码>

    <资源名称=“jdbc/exampleWeb”
        授权=“容器”
        类型=“javax.sql.DataSource”
        最大活动=“100”
        最大空闲=“30”
        用户名=“root”
        最大等待=“10000”
        driverClassName =“com.mysql.jdbc.Driver”
        密码=“root”  
        url="jdbc:mysql://localhost:3306/welcomeHub"/>
    

I think your application is not finding the mysql connector jar file or your url is misconfigured.

Try the following

  1. Put your mysql connector jar file under tomcat/common/lib so that it gets picked up before the webapp classes.
  2. Change your context.xml to have Resource as below.

    
    
    
    <Resource  name="jdbc/exampleWeb"
        auth="Container"
        type="javax.sql.DataSource"
        maxActive="100"
        maxIdle="30"
        username="root"
        maxWait="10000"
        driverClassName="com.mysql.jdbc.Driver"
        password="roopt"  
        url="jdbc:mysql://localhost:3306/welcomeHub"/>
    

半衬遮猫 2024-10-12 18:19:59

我在 DBCP 中看到过同样的错误,这通常意味着它找不到 JDBC 驱动程序...确保“com.mysql.jdbc.Driver”可用于容器

I've seen that same eror with DBCP and it usually means that it can't find the JDBC driver...make sure "com.mysql.jdbc.Driver" is available to the container

乖乖兔^ω^ 2024-10-12 18:19:59

我不明白为什么你需要 entityManagerFactorysessionFactory,通常只需要其中之一。

如果不需要 sessionFactory,请将其删除。否则请注意,其数据源未配置 - 我猜这是一个原因。

I can't understand why do you need both entityManagerFactory and sessionFactory, usually only one of them is needed.

If sessionFactory is not needed, remove it. Otherwise note that its datasource is not configured - I guess it's a cause.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文