1 报错信息
2022-03-08 11:46:30.050 [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - [refresh,591] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clickHouseServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'clusterClickHouseTemplate' defined in class path resource [com/idongyou/dongxin/common/datasource/config/JdbcDataSourceConfig.class]: Unsatisfied dependency expressed through method 'clusterClickHouseTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clusterClickHouseDataSource' defined in class path resource [com/idongyou/dongxin/common/datasource/config/JdbcDataSourceConfig.class]: Invocation of init method failed; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2022-03-08 11:46:30.052 [main] INFO c.a.d.p.DruidDataSource - [close,2071] - {dataSource-0} closing ...
2022-03-08 11:46:30.068 [main] INFO o.a.c.c.StandardService - [log,173] - Stopping service [Tomcat]
2022-03-08 11:46:30.108 [main] INFO r.y.c.ClickHouseDriver - [<clinit>,49] - Driver registered
2022-03-08 11:46:30.139 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - [report,40] -
***************************
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 (the profiles dev are currently active).
2022-03-08 11:46:30.140 [Thread-5] WARN c.a.n.c.n.NotifyCenter - [shutdown,136] - [NotifyCenter] Start destroying Publisher
2022-03-08 11:46:30.140 [Thread-1] WARN c.a.n.c.h.HttpClientBeanHolder - [shutdown,108] - [HttpClientBeanHolder] Start destroying common HttpClient
2022-03-08 11:46:30.140 [Thread-5] WARN c.a.n.c.n.NotifyCenter - [shutdown,153] - [NotifyCenter] Destruction of the end
2022-03-08 11:46:30.140 [Thread-1] WARN c.a.n.c.h.HttpClientBeanHolder - [shutdown,114] - [HttpClientBeanHolder] Destruction of the end
2 解决方法
1、检查nacos配置,添加对应的配置信息
clusterclickhouse:
driver-class-name: ru.yandex.clickhouse.ClickHouseDriver
url: jdbc:clickhouse://ip:port/dx_data
username: dev
password: dev
validationQuery: SELECT 1
2、检查数据源Bean名称,不能过长
修改前:
@Bean(name = "clusterClickHouseTemplate")
public JdbcTemplate clusterClickHouseTemplate(@Qualifier("clusterClickHouseDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
@Bean(name = "clusterClickHouseDataSource")
@Qualifier("clusterClickHouseDataSource")
@ConfigurationProperties(prefix = "spring.datasource.druid.clusterclickhouse")
public DataSource clusterClickHouseDataSource() {
return DruidDataSourceBuilder.create().build();
}
修改后:
@Bean(name = "clusterClickHouseTemplate")
public JdbcTemplate clusterClickHouseTemplate(@Qualifier("clusterChDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
@Bean(name = "clusterChDataSource")
@Qualifier("clusterChDataSource")
@ConfigurationProperties(prefix = "spring.datasource.druid.clusterclickhouse")
public DataSource clusterClickHouseDataSource() {
return DruidDataSourceBuilder.create().build();
}