java – 无法加载JDBC驱动程序.为什么? (春,休眠)

前端之家收集整理的这篇文章主要介绍了java – 无法加载JDBC驱动程序.为什么? (春,休眠)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在两周前通过Maven创建了一个程序(SPRING HIBERNATE),现在它在加载JDBC驱动程序时遇到了问题(直到现在才发生).所以,我的pom.xml文件如下所示:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.spring.hib</groupId>
    <artifactId>HibPav</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>2.5.6</version>
    </dependency>

<dependency>
    <groupId>MysqL</groupId>
    <artifactId>MysqL-connector-java</artifactId>
    <version>5.1.27</version>
</dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-hibernate3</artifactId>
      <version>2.0.5</version>
    </dependency>

        <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>

    <dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>jta</artifactId>
    <version>1.1</version>
    </dependency>

     <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>3.2.5.RELEASE</version>
       </dependency>

    <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>4.2.7.Final </version>
    </dependency>


    </dependencies>

</project>

看来这个文件很清楚.但是在我尝试创建dataSource bean时,无法加载JDBC驱动程序的主要问题是什么.

其他文件

数据源文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>properties/database.properties</value>
    </property>
</bean>

<bean id="dataSource"
         class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>

</beans>

属性文件

jdbc.driverClassName=com.MysqL.jdbc.Driver;
jdbc.url=jdbc:MysqL://localhost/mydb
jdbc.username=myinfuser
jdbc.password=myinfuserpw

错误

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring/database/datasource.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.MysqL.jdbc.Driver;]
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.applyPropertyValues(AbstractAutowireCapablebeanfactory.java:1279)
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.populateBean(AbstractAutowireCapablebeanfactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory$1.run(AbstractAutowireCapablebeanfactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:380)
    at org.springframework.beans.factory.support.Abstractbeanfactory$1.getObject(Abstractbeanfactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:261)
    at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:185)
    at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:164)
    at org.springframework.beans.factory.support.DefaultListablebeanfactory.preInstantiateSingletons(DefaultListablebeanfactory.java:429)
    at org.springframework.context.support.AbstractApplicationContext.finishbeanfactoryInitialization(AbstractApplicationContext.java:728)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.spring.dirba.Main.main(Main.java:11)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.MysqL.jdbc.Driver;]
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:104)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.applyPropertyValues(AbstractAutowireCapablebeanfactory.java:1276)
    ... 16 more

任何人?

提前致谢

解决方法

摆脱;在你的财产的最后
jdbc.driverClassName=com.MysqL.jdbc.Driver;

Spring使用反射和该属性的值来通过完全限定的类名加载Class实例.没有名为com.MysqL.jdbc.Driver;的类.有一个名为com.MysqL.jdbc.Driver的类,所以使用它.

jdbc.driverClassName=com.MysqL.jdbc.Driver
原文链接:https://www.f2er.com/java/127310.html

猜你在找的Java相关文章