關于使用spring.datasource.hikari連接配接資料庫找不到找不到url的問題
- applica.properties裡配置連接配接資料庫使用hikari
- 出現的問題異常
- 解決 配置重定義識别資料庫連接配接方式為spring.datasource.primary
- 完美解決
applica.properties裡配置連接配接資料庫使用hikari
#連結資料庫
spring.datasource.primary.jdbc-url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8 &serverTimezone=Asia/Shanghai
spring.datasource.primary.username=root
spring.datasource.primary.password=root
spring.datasource.primary.driver-class-name=com.mysql.cj.jdbc.Driver
出現的問題異常
Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.
未能配置資料源:未指定“url”屬性,也無法配置嵌入式資料源。
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-09-08 18:28:06.345 ERROR 7148 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
原因:springboot連接配接資料庫是預設的是 :spring.datasource為字首
解決 配置重定義識别資料庫連接配接方式為spring.datasource.primary
/**
* 使用spring.datasource.hikari為字首連接配接資料庫
* DataSource 預設為spring.datasource連接配接
*/
@Configuration
public class Dateresourse {
@Bean(name = "PrimaryDataSource") //作為一個bean對象并命名
@ConfigurationProperties(prefix = "spring.datasource.primary") //配置檔案中,該資料源的字首
public DataSource PrimaryDataSource() {
return DataSourceBuilder.create().build();
}
}
完美解決
