Closed kevinwang0224 closed 1 year ago
改动后的代码:
@Bean @ConfigurationProperties(prefix = "datasources.write") public DataSource writeDataSource() { return new HikariDataSource(); }
此处 HikariDataSource 的属性注入是在 org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor#postProcessBeforeInitialization 执行 。
org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor#postProcessBeforeInitialization
之前的代码:
@Bean @ConfigurationProperties(prefix = "datasources.write") public DataSource writeDataSource(DataSourceProperties properties) { return dataSource(properties); }
之前方法参数中注入的 DataSourceProperties 实际上就是以 spring.datasource 开头的配置,工程中没有配置,所以都为空。 报错也是因为 DataSourceProperties 为空,找不到 driverClassName ,详见 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties#determineDriverClassName
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties#determineDriverClassName
改动后的代码:
此处 HikariDataSource 的属性注入是在
org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor#postProcessBeforeInitialization
执行 。之前的代码:
之前方法参数中注入的 DataSourceProperties 实际上就是以 spring.datasource 开头的配置,工程中没有配置,所以都为空。 报错也是因为 DataSourceProperties 为空,找不到 driverClassName ,详见
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties#determineDriverClassName