我试图将“spring.sql.init.continue-on-error”属性添加到数据源,但它不起作用。这就是我正在尝试的,但缺少一些东西。这是一个扩展 Base 的类,但我只需要将此属性添加到
MyDataBaseConfig
我不想更改 Base。
@EnableConfigurationProperties
@Configuration
@XSlf4j
public class MyDataBaseConfig extends BaseDatabaseConfig {
@ConfigurationProperties("spring.sql.init.continue-on-error")
@Bean(name = "myDataSource")
public DataSource myDataSource() {
return super.dataSourceHikari();
}
除了通过 application.properties 将
spring.sql.init.continue-on-error
设置为 true
(如here所述)之外,您还可以尝试像这样配置 DataSourceInitializer
:
@EnableConfigurationProperties
@Configuration
@XSlf4j
public class MyDataBaseConfig extends BaseDatabaseConfig {
@Bean(name = "myDataSource")
public DataSource myDataSource() {
return super.dataSourceHikari();
}
@Bean
public DataSourceInitializer dataSourceInitializer() {
DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(myDataSource());
initializer.setContinueOnError(true); // This line sets the continueOnError property to true
return initializer;
}
}