我有一个当前使用*.properties文件的spring应用程序,我希望使用YAML文件.
我发现类YamlPropertiesFactoryBean似乎能够做我需要的.
我的问题是我不确定如何在我的Spring应用程序(使用基于注释的配置)中使用此类.看来我应该使用 setBeanFactory方法在PropertySourcesPlaceholderConfigurer中配置它.
以前我使用@PropertySource加载属性文件,如下所示:
@Configuration
@PropertySource("classpath:/default.properties")
public class PropertiesConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
Run Code Online (Sandbox Code Playgroud)
如何在PropertySourcesPlaceholderConfigurer中启用YamlPropertiesFactoryBean以便我可以直接加载YAML文件?还是有另一种方法吗?
谢谢.
我的应用程序使用基于注释的配置,我使用的是Spring Framework 4.1.4.我找到了一些信息,但它始终指向Spring Boot,就像这一样.