I use Spring Boot. I would like to write my configuration using YAML instead of properties.
Since I use spring-boot-starter
the SnakeYAML library is already in the classpath, and SpringApplication should use the YAML version automatically.
The SpringApplication class will automatically support YAML as an alternative to properties whenever you have the SnakeYAML library on your classpath.
The problem is that the application keep using the application.properties file and if I remove it no configuration are loaded at all.
Can someone help me? this is my main file
@SpringBootApplication
public class App {
public static void main(String[] args) throws Exception {
SpringApplication app = new SpringApplication(App.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
}
}
this is my pom.xml
....
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
the application.yml file is just
tasks: 231232
and I try reading the property using the injected environment
@Autowired
private Environment environment;
....
log.info(environment.getProperty("tasks"));
Where is my mistake?
String
which is annotated with@Value("${tasks}")
and check its value? - Arnaud Denoyelle