• Maven,预加载资源文件


    预加载资源文件需要先启用功能:

    <build>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering> 启用预加载,默认false
          </resource>
        </resources>
      </build>

    src/main/resources里,新增一个测试用的application.properties文件

    # application.properties
    application.name=${env.PATH}
    application.name=${settings.offline}
    application.name=${java.home}
    application.version=${pom.name}
    application.version=${project.version}

    先看普通效果,运行cmd

    mvn process-resources

    image

    被放到target/classes

    # application.properties
    application.name=C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;F:\MySQL\MySQL Server 5.1\bin;D:\Program Files\TortoiseSVN\bin;D:\Program Files\TortoiseGit\bin;d:\Program Files (x86)\Git\cmd;F:\apache-maven-3.2.3\bin;F:\Java\jdk1.8.0_25\bin;F:\HashiCorp\Vagrant\bin;F:\Tomcat 7.0\bin
    application.name=false
    application.name=F:\Java\jdk1.8.0_25\jre
    application.version=my-app
    application.version=1.0-SNAPSHOT

    现在新建个src/main/filters/filter.properties,用于预加载

    # filter.properties
    my.filter.value=hello!

    更改pom.xml:

    <build>
        <filters>指明预加载资源
          <filter>src/main/filters/filter.properties</filter>
        </filters>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
          </resource>
        </resources>
      </build>

    这时候就可以在application.properties中直接引用了

    message=${my.filter.value}

    就会变成:

    message=Hello!

    这样就实现了资源文件间的属性引用,而无需声明二者的关联(Spring?)

  • 相关阅读:
    有道云笔记隐藏ad控件
    commons-httpclient直接发送内存中byte[]文件
    springboot打包成zip部署,并实现优雅停机
    Java读取相对路径文件时,报FileNotFoundException异常
    Oracle 添加 scott 示例用户
    Usage and Idioms——Exception testing
    Usage and Idioms——Test execution order
    Usage and Idioms——Aggregating tests in suites
    Usage and Idioms——Test runners
    Usage and Idioms——Assertions
  • 原文地址:https://www.cnblogs.com/gcg0036/p/4149133.html
Copyright © 2020-2023  润新知