Как продолжить при ошибке для конфигурации собственной Кассандры в приложении Springboot - PullRequest
0 голосов
/ 11 июня 2019

У меня есть своя конфигурация cassandra в моем приложении весенней загрузки.Я хочу, чтобы мое весеннее загрузочное приложение продолжало работать даже в случае проблем с подключением к базе данных.

Пример: мой сервер базы данных cassandra не запущен.Приложение должно иметь возможность начать работу, игнорируя конфигурацию cassandra.

Пример кода конфигурации

package com.shivanshu.cassandrajpa.configuration;

import com.datastax.driver.core.PlainTextAuthProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;

/**
 * Created By shivanshu on 18/04/19 Apr, 2019
 */
@Configuration
@EnableCassandraRepositories(basePackages ="com.shivanshu")
public class CassandraConfig extends AbstractCassandraConfiguration {

    @Value("${cassandra.contactpoints}")
    private String contactPoints;

    @Value("${cassandra.port}")
    private int port;

    @Value("${cassandra.keyspace}")
    private String keyspaceName;

    @Value("${cassandra.username}")
    private String username;

    @Value("${cassandra.password}")
    private String passsword;

    @Value("${cassandra.clusterName}")
    private String clusterName;

    public String getKeyspaceName() {
        return keyspaceName;
    }

    @Bean
    public CassandraClusterFactoryBean cluster() {
        CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
        PlainTextAuthProvider sap = new PlainTextAuthProvider(username, passsword);
        cluster.setContactPoints(contactPoints);
        cluster.setPort(port);
        cluster.setClusterName(clusterName);
        cluster.setAuthProvider(sap);
        cluster.setJmxReportingEnabled(false);
        return cluster;
    }
}
...