是否可以在常规application.yml(Java Springboot)旁边有一个yml配置文件
我有一个带有application.yml的应用程序,但我需要另一个名为foo.yml的配置文件。我似乎无法让它工作。我的代码怎么了是否可以在常规application.yml(Java Springboot)旁边有一个yml配置文件,java,spring-boot,yaml,Java,Spring Boot,Yaml,我有一个带有application.yml的应用程序,但我需要另一个名为foo.yml的配置文件。我似乎无法让它工作。我的代码怎么了 @ConfigurationProperties(prefix = "test") @Configuration @PropertySource(value = "classpath:foo.yml") public class All { String oof; // getters and setters
@ConfigurationProperties(prefix = "test")
@Configuration
@PropertySource(value = "classpath:foo.yml")
public class All {
String oof;
// getters and setters and toString
}
我的foo.yml
test:
oof: "bloof"
我的测试,其中oof输出为null而不是bloof
@ExtendWith(SpringExtension.class)
@SpringBootTest
class AllTest {
@Autowired
private All all;
@Test
public void test {
System.out.println(all.toString());
}
}
因为@PropertySourcevalue=…不支持.yml。。
从…起
:
支持传统和基于XML的属性文件格式,例如,classpath:/com/myco/app.properties或file:/path/to/file.XML
为什么不使用profiles,命名为application foo.yml?我刚刚试过,但仍然不起作用,所以我开始认为我在测试中弄错了什么?你看到什么问题了吗?这回答了你的问题吗?@yAzou是的,谢谢。这回答了你的问题吗?