【问题标题】:Multiple data sources with spring data - need to set the property continueOnErrorspring数据多数据源 - 需要设置属性 continueOnError
【发布时间】:2018-01-25 22:13:56
【问题描述】:

我在 Spring Boot 中使用两个数据源和 Spring 数据。 有一个选项可以通过属性文件spring.datasource.continueOnError=true设置属性

我的要求是仅为一个数据源设置此属性,如果另一个数据源关闭,我需要关闭应用程序。 如何将此属性设置为我需要跳过应用程序正在关闭的数据源?

请找到我的数据源配置

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

【问题讨论】:

    标签: java spring spring-boot spring-data-jpa datasource


    【解决方案1】:

    相信你想要spring.datasource.primary.continueOnError=true

    【讨论】:

      猜你喜欢
      • 2017-05-06
      • 1970-01-01
      • 1970-01-01
      • 2011-06-12
      • 2020-09-13
      • 1970-01-01
      • 2018-01-25
      • 2013-05-04
      • 1970-01-01
      相关资源
      最近更新 更多