如何设置 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.[=15= 创建配置文件]
对不起
更新
我正在使用这个
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")
};
我很困惑如何为外部配置设置位置,
基于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.[=15= 创建配置文件]
对不起
更新
我正在使用这个
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")
};