我正在使用yml
文件来配置数据源。但在执行jar文件后,我得到了异常。如果我从IntelliJ运行项目,yml
工作正常
application.yml
spring:
datasource:
url: jdbc:postgresql://localhost:5332/dbName
username: username
password: password
driverClassName: org.postgresql.Driver
例外情况
05:13:50.339 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Failed to determine a suitable driver class
但如果我通过Kotlin配置,它就能工作
@Configuration
class Config {
@Bean
fun getDataSource(): DataSource {
val dataSourceBuilder = DataSourceBuilder.create()
dataSourceBuilder.driverClassName("org.postgresql.Driver")
dataSourceBuilder.url("jdbc:postgresql://localhost:5332/dbName")
dataSourceBuilder.username("username")
dataSourceBuilder.password("password")
return dataSourceBuilder.build()
}
}
1条答案
按热度按时间72qzrwbm1#
取出您的自定义jar似乎解决了这个问题。