org.apache.tomcat.dbcp.dbcp.SQLNestedException:无法为连接URL'null'创建类''的JDBC驱动程序

时间:2010-12-02 06:35:51

标签: mysql hibernate spring jpa jndi

我正在使用spring,hybernate + jpa开发基于Web的项目。我正在尝试使用Atomkios配置JTA事务    我的后端是mySql。我无法设置应用程序以使用mySql。     我的网络服务器是tomcat 5.5。我正在尝试cal 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中配置了jndi

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> 

我的服务器很好,但是当我尝试访问数据库时,我的网页浏览器出现以下错误

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

帮帮我

3 个答案:

答案 0 :(得分:2)

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

尝试以下

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

    
    
    
    <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"/>
    

答案 1 :(得分:0)

我无法理解为什么你需要entityManagerFactorysessionFactory,通常只需要其中一个。

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

答案 2 :(得分:0)

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