簡體   English   中英

如何設置PropertySourcesPlaceholderConfigurer Auto SetLocations for External Configuration in Java Spring Boot

[英]How to setting PropertySourcesPlaceholderConfigurer Auto SetLocations for External Configuration in Java Spring Boot

我很困惑如何為外部配置設置位置,

基於https://docs.spring.io/spring-boot/docs/1.2.2.RELEASE/reference/html/boot-features-external-config.html我做了一些外部配置但失敗了,這是我的代碼

package com.org.tre.myth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

@Configuration
public class ExternalPropertyConfig {


@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
final PropertySourcesPlaceholderConfigurer properties = new PropertySourcesPlaceholderConfigurer();

Resource[] resources = new Resource[ ] {
        new ClassPathResource("/myth/app/data/weblogic_configuration/config/conf.properties"), // i want this config used when i deploy it in dev
        new FileSystemResource("src/main/resources/conf.properties") // i want this config used when in local test
};

properties.setLocations( resources );
properties.setIgnoreResourceNotFound(true);
properties.setIgnoreUnresolvablePlaceholders(false);
return properties;
 }
}

它總是在 FileSystemResource 上運行,當我部署時,它不想在開發時自動從 ClassPathResource 讀取。 我的配置實際上具有相同的內容(開發和測試),不同之處在於目錄,因為我的開發人員做了一些分層,我希望配置自動運行,甚至沒有為 spring 創建配置文件。

對不起

更新

我用這個

Resource[] resources = new Resource[ ] {
            new FileSystemResource("/myth/app/data/weblogic_configuration/config/conf.properties"),
            new FileSystemResource("src/main/resources/conf.properties")
    };

使用這個

Resource[] resources = new Resource[ ] {
            new FileSystemResource("/myth/app/data/weblogic_configuration/config/conf.properties"),
            new FileSystemResource("src/main/resources/conf.properties")
    };

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM