OssConfigration.java 1.59 KB
package com.vion.configuration;


import com.vion.dao.IDao;
import com.vion.dao.MyFaceDao;
import com.vion.dao.PostFaceDao;
import com.vion.entity.OssClientEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;


/**
 * @author 谢明辉
 * @createDate 2018-10-30
 * @description
 */
@Configuration
public class OssConfigration {

    @Value("${oss.config.endPoint}")
    private String endPoint;
    @Value("${oss.config.accessKeyId}")
    private String accessKeyId;
    @Value("${oss.config.accessKeySecret}")
    private String accessKeySecret;
    @Value("${oss.config.bucket}")
    private String bucket;

    public static int COUNT = 0;


    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public OssClientEntity ossClientEntity() {
        OssClientEntity entity = new OssClientEntity();
        entity.setKey(accessKeyId);
        entity.setSecret(accessKeySecret);
        entity.setEndPoint(endPoint);
        entity.setBucket(bucket);
        return entity;
    }

    @Bean("Dao")
    @ConditionalOnProperty(name = "flag", havingValue = "mysql")
    public IDao myFaceDao() {
        return new MyFaceDao();
    }

    @Bean("Dao")
    @ConditionalOnProperty(name = "flag", havingValue = "postgre")
    public IDao postFaceDao() {
        return new PostFaceDao();
    }
}