SpringBoot项目初始化

@SpringBootApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
@EnableTransactionManagement
public class SvcServerApplication {

public static void main(String[] args) {

    SpringApplication springApplication = new SpringApplication(SvcServerApplication.class);
    springApplication.addListeners(new SvcListeners());
    springApplication.run(args);

    // 测试main方法注入bean,项目中不要执行,注释掉

// TestService testService = ApplicationContextHelper.getBean(TestService.class);
// testService.testMain(10);
}
}

//监听器
public class SvcListeners implements ApplicationListener {

@Override
public void onApplicationEvent(ApplicationStartedEvent e) {

    Environment environment = ApplicationContextHelper.applicationContext.getEnvironment();
    try {
        // magpie启动监听
        new BootStrap().start(environment.getProperty("magpie.path"));

        // 全渠道sdk装配
        SDKConfig.getConfig().loadPropertiesFromPath(environment.getProperty("acp.sdk.properties.path"));

        String smsTag = environment.getProperty("smsConnect");
        if ("1".equals(smsTag)) {
            // 生产环境初始化短信客户端,开启短信发送功能;测试环境关闭短信功能
            UPMMClient.init(new SmsListener(), true);
        }
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    }

    // 启动A B Cache 内存块更新内存常用业务参数
    DualBlockCache.getInstance().start(environment.getProperty("cardBin.dir"));

    // TODO: 2018/8/16 上线时给logback-spring.xml中的46行 <appender-ref ref="STDOUT" /> 打上注释,关闭日志控制台输出

    // 项目启动后加载配置文件参数进内存
    PropertyUtils.loadProps();
}

}

//定时器任务
public void start(String cardBinDir) {

    // 根据卡bin构建Darts
    try {
        // 读文件,装配list
        Timestamp start = new Timestamp(System.currentTimeMillis());
        logger.info("根据卡bin构建Darts,任务开始");
        BufferedReader reader = new BufferedReader(new FileReader(cardBinDir));
        String line;
        // words 存储 cardBin
        List<String> words = new ArrayList<>();
        while ((line = reader.readLine()) != null) {
            words.add(line.substring(0, line.indexOf(",")));
            cardBinList.add(line);
        }
        reader.close();
        logger.info("cardBin字典词条: " + words.size());

//定时器任务2
/**
* 将配置文件所有属性值读入内存,项目运行时不再读文件
*/
public static void loadProps() {

    Properties prop = new Properties();
    InputStream in = null;
    try {
        Environment environment = ApplicationContextHelper.applicationContext.getEnvironment();
        in = new BufferedInputStream(new FileInputStream(environment.getProperty("conf.file.path")));
        //prop.load(in);
        prop.load(new InputStreamReader(in, "utf-8"));
        if (prop.containsKey("workerId") && prop.containsKey("datacenterId")
                && prop.containsKey("orderIdMachineCode") && prop.containsKey("passiveBackUrl")
                && prop.containsKey("addnOpUrl")) {
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值