gpt4 book ai didi

java.lang.IllegalStateException : Cannot load driver class: com. microsoft.sqlserver.jdbc.SQLServerDriver

转载 作者:行者123 更新时间:2023-12-02 09:13:59 25 4
gpt4 key购买 nike

我在 IDE IntelliJ 上使用 spring boot 创建了这个 java 应用程序以下是我的配置文件。应用程序构建成功,但出现此错误:

Caused by: java.lang.IllegalStateException: Cannot load driver class: com.microsoft.sqlserver.jdbc.SQLServerDriver

解决了这个问题,
将 jar 添加到类路径但不起作用
应用程序属性

# port
server.port=7031

# ms sql database
spring.datasource.url=jdbc:sqlserver://0.0.0.0:1433;databaseName=PEOPLEHUM
spring.datasource.username=sa
spring.datasource.password=mssql@123
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.hibernate.ddl-auto=update

spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

spring.batch.job.enabled=false

# cron value for executor
scheduled.job.attendance.logs.cron=0 0 0/12 ? * *

# Logging pattern for file
logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%

# output to a C:/peoplehum/logs/
logging.path=C:/peoplehum/logs/
logging.file=C:/peoplehum/logs/logs.log
logging.file.max-size=10MB

构建.gradle

plugins {
id 'org.springframework.boot' version '2.2.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}

group = 'com.peoplehum'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-web'

runtimeOnly 'org.springframework.boot:spring-boot-devtools'
compile group: 'net.sf.ucanaccess', name: 'ucanaccess', version: '4.0.4'
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.4'
compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.3.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.12.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.12.1'
testCompile group: 'com.microsoft.sqlserver', name: 'sqljdbc4', version: '4.0'

compile("org.springframework.boot:spring-boot-starter-data-jpa")

compileOnly 'org.projectlombok:lombok'

annotationProcessor 'org.projectlombok:lombok'

testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}

test {
useJUnitPlatform()
}

bootJar {
launchScript()
}

我已经在网络上尝试了许多可用的解决方案,但没有一个对我有用

根据 Zakir 的建议,我更新了驱动程序依赖项,但仍然出现以下错误:抱歉,已经尝试过

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.microsoft.sqlserver.jdbc.SQLServerDriver

最佳答案

使用更新的 jar 并更改 gradle 依赖项,如下所示:

testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.1.0.jre7'

来源:https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc/6.1.0.jre7

关于java.lang.IllegalStateException : Cannot load driver class: com. microsoft.sqlserver.jdbc.SQLServerDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59151061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com