package com.usoft.credit;

import com.usoft.credit.config.EncryptablePropertyPlaceholderConfigurer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.Resource;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author liuam
 * @since 2018/8/7 0007 上午 9:52
 */
@EnableTransactionManagement
@SpringBootApplication(scanBasePackages = {"com.usoft.credit"})
@MapperScan("com.usoft.credit.dal")
public class CreditGrpcApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(CreditGrpcApplication.class);
    }

    @Bean
    @Profile("prod")
    public PropertyPlaceholderConfigurer prod(ApplicationContext applicationContext) {
        PropertyPlaceholderConfigurer configurer = new EncryptablePropertyPlaceholderConfigurer();
        Resource resource = applicationContext.getResource("classpath:prod.properties");
        configurer.setLocation(resource);
        return configurer;
    }

    @Bean
    @Profile("dev")
    public PropertyPlaceholderConfigurer dev(ApplicationContext applicationContext) {
        PropertyPlaceholderConfigurer configurer = new EncryptablePropertyPlaceholderConfigurer();
        Resource resource = applicationContext.getResource("classpath:dev.properties");
        configurer.setLocation(resource);
        return configurer;
    }
}
