我的应用程序是基于弹簧的,我想从中央服务器加载 yml 文件,但无法这样做。
我的 yml 文件是这样的:
spring:
application:
name: signed-in-web
cloud:
config:
uri: ${server.url}
health:
config:
enabled: false
注意: server.url 在 vm 选项中定义。我从休息客户端检查了属性在服务器上是否有效且可用。
然后我尝试将它复制到这样的属性文件中:application.properties
LOCATION_SEARCH=${properties.app.api-key.location-search}
我有这样的java配置类:
@Profile("!test")
@ComponentScan(basePackages = { "com.company.frontend.*" })
@Configuration
@PropertySource("classpath:properties/qa_env.properties")
public class propertiesConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
yaml.setResources(new ClassPathResource("bootstrap.yml"));
propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject());
return propertySourcesPlaceholderConfigurer;
}
}
我认为这将加载这样的配置:
@Value("${LOCATION_SEARCH}")
public static String LOCATION_SEARCH;
但我越来越空了。不知何故,我无法找到问题所在。将要