错误信息如下:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: org.postgresql.Driver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader
配置的database链接信息如下:
spring.datasource.url=jdbc:postgresql://localhost:5433/springbootdb
spring.datasource.username=postgres
spring.datasource.password=${POSTGRES_PASSWORD:postgres@123}
maven的pom文件里和postgre相应的dependency有如下两个
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
<scope>test</scope>
</dependency>
<profile>
<id>postgres</id>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<profiles>
<profile>postgres</profile>
<profile>localhost</profile>
</profiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
原因在于:第一个和postgres相关的configuration的scope是test,因此在编译的时候这个dependency是不会生效的,而第二个postgres的dependency指定了profile: <profile> <id>postgres</id>, 因此在编译时如果不指定Postgres的profile,这个dependency就找不到了.
因此在运行命令的时候我们需要指定maven的profile为
-Ppostgres
这样这个postgres的dependency就能找到了