读取properties配置的工具类

时间:2022-02-12 03:38:47
@Service
public class AppPropertiesManager implements DisposableBean{
    @Value("${shortloan_rate_1}")
    private  Double shortloanRate1Year;

    @Value("${longloan_rate_1_5}")
    private  Double longloanRate1to5Year;

    @Value("${fcffT}")
    private  Double fcffT;

    @Value("${risk_premium}")
    private Double risk_premium;

    public Double getRisk_premium() {
        return risk_premium;
    }

    public void setRisk_premium(Double risk_premium) {
        this.risk_premium = risk_premium;
    }

    public String getGuidDomain() {
        return guidDomain;
    }

    public void setGuidDomain(String guidDomain) {
        this.guidDomain = guidDomain;
    }

    @Value("${cookie_guid_domain}")
    private  String guidDomain;

    public Double getFcffT() {
        return fcffT;
    }

    public void setFcffT(Double fcffT) {
        this.fcffT = fcffT;
    }

    public Double getShortloanRate1Year() {
        return shortloanRate1Year;
    }

    public void setShortloanRate1Year(Double shortloanRate1Year) {
        System.out.println(shortloanRate1Year);
        this.shortloanRate1Year = shortloanRate1Year;
    }

    public Double getLongloanRate1to5Year() {
        return longloanRate1to5Year;
    }

    public void setLongloanRate1to5Year(Double longloanRate1to5Year) {
        this.longloanRate1to5Year = longloanRate1to5Year;
    }

    /**
     * 开发时用来查看配置是否生效
     * Invoked by a BeanFactory on destruction of a singleton.
     *
     * @throws Exception in case of shutdown errors.
     *                   Exceptions will get logged but not rethrown to allow
     *                   other beans to release their resources too.
     */
    @Override
    public void destroy() throws Exception {
        System.out.println(longloanRate1to5Year);
        System.out.println(shortloanRate1Year);
        System.out.println(guidDomain);
    }
}

在web工程中,部署时,properties通常在WEB-INF\classes下,与class文件同级,该工具类可以是在jar包里面,可以正常读取到properties。