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

com.luoshu.open.id.IdAutoConfiguration Maven / Gradle / Ivy

package com.luoshu.open.id;

import com.luoshu.open.id.exception.IdException;
import org.luoshu.util.Assert;
import org.luoshu.util.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * ID 自动配置
 * @author inme
 */
@Configuration
public class IdAutoConfiguration {


    @Bean
    @ConditionalOnMissingBean(IdFactory.class)
    public IdFactory idFactory(LuoshuIdProperties properties){
        if(properties.getJdbc() == null){
            throw new IdException("luoshu-id datasource not configuration");
        }
        if(StringUtils.isBlank(properties.getJdbc().getUrl())){
            throw new IdException("luoshu-id datasource not configuration");
        }
        DataSource dataSource = SqlUtil.createOrGetDataSource(properties);
        IdFactory idFactory = IdFactoryBuilder.buildJdbcFactory(dataSource, true);
        return idFactory;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy