I have a multi module Spring Boot project with the following structure:
- MyAppModule
- src/main/java/Application.java
- ...
- IntegrationTests
- src/test/java/integrationTest.java
The IntegrationTest module is testing the MyAppModule. The IntegrationTest module does not have a main package. Therefore there is no Spring Application. It has just the test package.
Nevertheless I would like to read in the application.yaml for some properties but I'm not able to because the attributes are always null:
@Configuration
@PropertySource("classpath:application.yaml")
public class IntegrationTest {
@Value("${app.url}")
private String appUrl;
}
Isn't it possible to use the @Value annotation without having a Spring Application (main with SpringApplication.run etc.)?
@PropertySourceis only for.propertiesfile not for loading.yamlfiles. Yes it is possible, no it isn't working (neither in Spring Boot) for YAML files.