无法加载驱动程序类

无法加载驱动程序类

本文介绍了无法加载驱动程序类:com.microsoft.jdbc.sqlserver.SQLServerDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行Spring启动应用程序时遇到异常,它说无法创建数据源bean,导致此异常的原因是它无法检测到SQLServer的DriverClass。

I am getting an exception while running my spring boot application, it say unable to create bean of datasource and caused of this exception is that it unable to detect my DriverClass for SQLServer.

这是我的application.properties文件:

Here is my application.properties file:

spring.jpa.database-platform=org.hibernate.dialect.SQLServerDialect
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driverClassName=com.microsoft.jdbc.sqlserver.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=dbname
spring.datasource.username=name
spring.datasource.password=****

我已经下载了sqljdbc连接器jar并将其放在lib文件夹中并在我的pom.xml文件中提供它的引用。

I have downloaded it sqljdbc connector jar and put it in the lib folder and give its reference in my pom.xml file.

    <?xml version="1.0" encoding="UTF-8"?>
<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.myproject</groupId>
<artifactId>myproject-notifications</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>netpace-notifications</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.8.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-dbcp2</artifactId>
            <version>2.1.1</version>

        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/sqljdbc4-2.0.jar</systemPath>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

我尝试过使用这些标签:

I have tried using these tags:

<dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>sqljdbc4</artifactId>
        <version>4.0</version>
    </dependency>

但它在我的pom.xml文件中出错,这就是为什么我必须使用其他方法。我是新手,如果有人让我知道我在这里做错了什么,我会非常感激。
提前致谢。

But it is giving error in my pom.xml file so that why I have to use the other approach. I am new to spring and would be very thankful if somebody let me know what I am doing wrong here.Thanks in advance.

推荐答案

您正在尝试加载错误的驱动程序。名称 com.microsoft.jdbc.sqlserver.SQLServerDriver 的驱动程序来自非常旧的SQL Server 2000 JDBC驱动程序。

You are trying to load the wrong driver. The driver with name com.microsoft.jdbc.sqlserver.SQLServerDriver is from the very old SQL Server 2000 JDBC driver.

在SQL Server 2005 JDBC驱动程序中,Microsoft将此更改为 com.microsoft.sqlserver.jdbc.SQLServerDriver (请注意 sqlserver之间的顺序切换 jdbc

In the SQL Server 2005 JDBC driver, Microsoft changed this to com.microsoft.sqlserver.jdbc.SQLServerDriver (note the switch of order between sqlserver and jdbc.

附注:您使用的是旧版本的驱动程序Microsoft已开源,它在maven上可用:

Side note: you are using an old version of the driver. Microsoft has open sourced the SQL Server JDBC driver and it is available on maven as:

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>6.2.2.jre8</version>
</dependency>

这篇关于无法加载驱动程序类:com.microsoft.jdbc.sqlserver.SQLServerDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 03:25