@Component 扫描类,在方法中的函数中用@PostConstruct 注解。
package com.hengqin.life.product.proxy.tools;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import lerrain.project.insurance.product.InsuranceCompany;
import lombok.extern.slf4j.Slf4j;
/**
* 产品中心缓存
*/
@Slf4j
@Component
public class ProductCache {
/**
* 从配置文件中取 配置文件路径
*/
@Value("${product.config.fileLocation}")
private String fileLocation;
/**
* 单例缓存类
*/
private static InsuranceCompany cache;
private ProductCache(){
log.info("加载配置信息");
}
/**
* 应用启动的执行初始化
*/
@PostConstruct
private void init(){
log.info("配置文件路径: {}" , fileLocation);
cache = ProductSupport.load(fileLocation,"hengqin");
}
/**
* 静态返回 返回产品缓存
* @return
*/
public static InsuranceCompany getInsuranceCompany(){
return cache;
}
}