spring.config.additional-場所を作業しないでください

イアンBurtovoy:

Mavenの:

<profiles>
    <profile>
        <id>local</id>
        <activation>
           <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <active.spring.profile>local</active.spring.profile>
        </properties>
    </profile>
</profiles>

application.properties:

[email protected]@
spring.config.additional-location=classpath:/profile/application-${spring.profiles.active}.properties

そしてこの後、私は含まれていSRC /メイン/リソース/ application-local.propertiesから値を取得することはできません test.prop=123

@Service
public class TestProps {

    @Value("${test.prop}")
    String testProp;

    @PostConstruct
    void run() {
        System.out.println(testProp);
    }
}

間違いはどこですか?またはそれはバグですか?

user10639668:

プロパティは:spring.config.additional-locationこのようなプログラムの引数として提供する必要があります:java -jar whatever.jar --spring.config.additional-location=classpath:/profile/application-local.properties

でそれを持ってしても意味がありませんapplication.properties以下からのドキュメント

カスタム設定位置はspring.config.additionalロケーションを使用して構成されている場合あるいは、それらはデフォルトの場所に加えて使用されています。追加の場所はデフォルトの場所の前に検索されます

追加の場所が検索されているので前に、デフォルトの場所あなたがそれらを持つことができないので、彼らは、以前提供されなければなりませんapplication.properties

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=196928&siteId=1