Java Spring Boot Hikari 找不到 DriverClassName
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51394201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring Boot Hikari can't find DriverClassName
提问by Gusti Arya
I have a spring boot project,It run just fine when I execute via eclipse Project > Run as > spring boot app
我有一个spring boot项目,当我通过eclipse执行时它运行得很好 Project > Run as > spring boot app
but when I build the project and execute it using java -jar myproject.jar
or run it using mvn spring-boot:run
it throw this error
但是当我构建项目并java -jar myproject.jar
使用mvn spring-boot:run
它执行或使用它运行它时会抛出此错误
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: com.microsoft.sqlserver.jdbc.SQLServerDriver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class com.microsoft.sqlserver.jdbc
.SQLServerDriver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
my sql server connector dependency
我的 sql server 连接器依赖项
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
<scope>test</scope>
</dependency>
and here my application.properties
这里是我的 application.properties
spring.datasource.url=jdbc:sqlserver://mydb;databaseName=HTSdb
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
it looks my app can't find the sqlserver driver but it is already in project classpath,any suggestion? thanks in advance
看起来我的应用程序找不到 sqlserver 驱动程序,但它已经在项目类路径中,有什么建议吗?提前致谢
采纳答案by vb.stack
I think the issue is with dependency scope which is set as test.
我认为问题在于设置为test 的依赖范围。
Scope testindicates that dependency isn't required at standard runtime of application and should only be used for purpose of test runs only!
范围测试表明在应用程序的标准运行时不需要依赖项,只能用于测试运行的目的!
Usually database connectors dependency are set with runtimescope.
通常数据库连接器依赖是用运行时范围设置的。
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
<scope>runtime</scope>
</dependency>