spring boot 加载自定义properties



因为项目重构的需要,对Excel的导入,进行解耦合,自定义properties进行表格说明

#这里进行模板病例的配置,后台进行读取.
#只需要在这里进行配置,不需要改代码了.这就是目标
#病例信息
excel.caseInfo=1
#患者概述
excel.patientInfo=2

关于conf.properties的加载.需要进行一下的设置.

@Component
@PropertySource(value = "conf.properties")
public class PropertiesResources {

    /**
     * 病例信息
     */
    @Value("${excel.caseInfo}")
    public int caseInfo;
    /**
     * 患者概述
     */
    @Value("${excel.patientInfo}")
    public int patientInfo;
}

这里进行加载配置文件,同时进行赋值.因为不想写private所以就直接使用了public了.这里写int能够转换过来的,
不用担心,这样,这个实体类中就有数值了.

如果加载不成功就需要再pom.xml中配置:
<resources>
    <resource>
        <targetPath>BOOT-INF/lib/</targetPath>
        <directory>${basedir}/lib/</directory>
        <includes>
            <include>**/*.jar</include>
        </includes>
    </resource>
    <resource>
        <directory>${basedir}/src/main/java</directory>
        <targetPath>BOOT-INF/classes/</targetPath>
        <filtering>true</filtering>
        <includes>
            <include>**/*.xml</include>
            <include>**/*.properties</include>
        </includes>
    </resource>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
    </resource>
</resources>


还有45分钟,就放假了,今天医学部的人说我这两天好像老了好多,唉,是啊,老了好多.


猜你喜欢

转载自blog.csdn.net/u010398771/article/details/80137286