使用XML config,我一直在使用这种结构:
<context:annotation-config/><bean id="yamlProperties" > <property name="resources" value="classpath:test.yml"/></bean><context:property-placeholder properties-ref="yamlProperties"/>
当然,您必须对运行时类路径具有snakeyaml依赖性。
我更喜欢XML配置而不是Java配置,但我认为转换它应该不难。
编辑:
java config为完整性起见
@Beanpublic static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer(); YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean(); yaml.setResources(new ClassPathResource("default.yml")); propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject()); return propertySourcesPlaceholderConfigurer;}


