相关疑难解决方法(0)

如何使用YamlPropertiesFactoryBean使用Spring Framework 4.1加载YAML文件?

我有一个当前使用*.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,就像一样.

java spring yaml properties-file

35
推荐指数
3
解决办法
6万
查看次数

标签 统计

java ×1

properties-file ×1

spring ×1

yaml ×1