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;
}