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

com.codingapi.tx.config.ConfigReader Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show newest version
package com.codingapi.tx.config;

import com.codingapi.tx.config.service.TxManagerTxUrlService;
import com.lorne.core.framework.utils.config.ConfigUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * create by lorne on 2017/11/13
 */
@Component
public class ConfigReader {


    private Logger logger = LoggerFactory.getLogger(ConfigReader.class);


    private TxManagerTxUrlService txManagerTxUrlService;

    @Autowired
    private ApplicationContext spring;


    public String getTxUrl() {

        try {
            txManagerTxUrlService =  spring.getBean(TxManagerTxUrlService.class);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
        }

        if(txManagerTxUrlService == null){
            txManagerTxUrlService = new TxManagerTxUrlService() {

                private final String configName = "tx.properties";

                private final String configKey = "url";

                @Override
                public String getTxUrl() {
                    return ConfigUtils.getString(configName,configKey);
                }
            };

            logger.info("load default txManagerTxUrlService");
        }else{
            logger.info("load txManagerTxUrlService");
        }

        return txManagerTxUrlService.getTxUrl();
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy