代码之家  ›  专栏  ›  技术社区  ›  Tristan

如何在fatjar中没有相应的default.properties文件的情况下拥有外部spring boot config.properties文件?

  •  0
  • Tristan  · 技术社区  · 5 年前

    我想要一个代币“private.properties“我希望这个.properties文件只在运行时提供,我不想把这个文件放在我的.jar中

    所以我把它排除在我的包装里:

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>**/private.properties</exclude>
                </excludes>
            </resource>
        </resources> 
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    

    $ java -Dspring.config.additional-location=file:./config/private.properties -jar target/mytool-1.0.0-SNAPSHOT.jar
    

    java.io.FileNotFoundException: class path resource [private.properties] cannot be opened because it does not exist
    

    如果有空的“private.properties“不排除包装,它的作品。

    只有一个外部的private.properties ?

    下面是我在中声明文件位置的方法PrivateProperties.java :

    @PropertySource("classpath:/private.properties")
    

    我需要硬编码吗private.properties 工作地点?

    0 回复  |  直到 5 年前