私のアプリケーションは春に基づいており、集中型サーバーからymlファイルをロードしたいが、そうすることはできない。Spring Frameworkを使用してYAMLファイルを使用するには?
マイ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;
しかし、私はnullになっています。どういうわけか私は問題がどこにあるかを見つけることができませんでした。 Will