1
我在弹簧数据的弹簧引导中使用了两个数据源。 有一个选项,通过属性文件设置属性spring.datasource.continueOnError=true
带有弹簧数据的多个数据源 - 需要设置属性continueOnError
我的要求是设置此属性只有一个数据源,如果另一个是关闭我需要使应用程序关闭。 如何将此属性设置为我需要跳过应用程序的数据源正在关闭?
请找我的数据源配置
@Bean
public LocalContainerEntityManagerFactoryBean webNotifyEntityManager() {
final LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean =
new LocalContainerEntityManagerFactoryBean();
localContainerEntityManagerFactoryBean.setDataSource(webNotifyDataSource());
localContainerEntityManagerFactoryBean.setPackagesToScan(Constants.WEBNOTIFY_REPOSITORIES);
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
localContainerEntityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter);
final HashMap<String, Object> properties = new HashMap<>();
properties.put("hibernate.dialect", hibernateDialect);
properties.put("hibernate.show_sql", true);
localContainerEntityManagerFactoryBean.setJpaPropertyMap(properties);
return localContainerEntityManagerFactoryBean;
}
@Primary
@Bean
public DataSource webNotifyDataSource() {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(Preconditions.checkNotNull(driverClassName));
dataSource.setUrl(Preconditions.checkNotNull(webNotifyUrl));
dataSource.setUsername(Preconditions.checkNotNull(webNotifyUserName));
dataSource.setPassword(Preconditions.checkNotNull(webNotifyPassword));
return dataSource;
}
@Primary
@Bean
public PlatformTransactionManager webNotifyTransactionManager() {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(webNotifyEntityManager().getObject());
return transactionManager;
}