All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.spider.autoswitching.basis.bean.SpringConfigurableEnvironmentDataSourceCreateable Maven / Gradle / Ivy

The newest version!
package com.spider.autoswitching.basis.bean;

import com.spider.autoswitching.Createable;
import com.spider.autoswitching.bind.ConfigurationPropertiesBinding;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;

import javax.sql.DataSource;
import java.util.Set;

/**
 * 通过 spring 环境配置 创建DataSource
 *
 * @author liuzhongkai
 */
public class SpringConfigurableEnvironmentDataSourceCreateable implements Createable {

    private ConfigurationPropertiesBinding binding;

    private Set prefixSet;

    private Class type;


    public SpringConfigurableEnvironmentDataSourceCreateable(ConfigurationPropertiesBinding binding, Class type, Set prefixSet) {
        this.binding = binding;
        this.prefixSet = prefixSet;
        this.type = type;
    }

    @Override
    public T create() {
        DataSourceProperties properties = new DataSourceProperties();
        prefixSet.forEach(item -> binding.bind(properties, item));
        T dataSource = properties.initializeDataSourceBuilder().type(type).build();
        prefixSet.forEach(item -> binding.bind(dataSource, item));
        return dataSource;
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy