springboot从自定义配置文件中取值
1.自定义文件selfdefine.properties:
pdf.templatePath=E:\\shengtingPDF\\src\\main\resources\\pdflocation\\
pdf.newPDFPath=E:\\shengtingPDF\\src\\main\resources\\pdflocation\\
pdf.fontpath=c://windows//fonts//simsun.ttc
2.创建获取类:Pdf.class
package com.nsgf.pm.legalmanager.fileUpload.resource;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
/**
* @Author: bsm
*/
@Component
@ConfigurationProperties(prefix = "pdf")
@PropertySource("classpath:selfdefine.properties")
@Data
public class Pdf {
private String newPDFPath;
private String templatePath;
private String fontpath;
}
3.在需要获取属性值的类中注入pdf并且调用获取:
public class PdfUtils {
@Autowired