Spring boot не подгружает application.yml.
Пробовал использовать @Value, @ConfigurationProperties, @EnableConfigurationProperties, @PropertySource("classpath:src/main/resources/application.yml"), snakeyaml library - результат test = null
Подскажите пожалуйста где ошибка.
// Application.java
package com.my.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = "com.my")
public class Application
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
}
// TestClass.java
package com.my.application;
public class TestClass
{
public TestClass()
{
}
}
//ApplicationConfiguration
package com.my.configuration;
import com.my.application.TestClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
@Configuration
public class ApplicationConfiguration
{
@Autowired
Environment env;
@Bean TestClass getTestClass()
{
System.out.println(env.getProperty("test"));
return new TestClass();
}
}
// pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my</groupId>
<artifactId>test</artifactId>
<version>1.3.0</version>
<packaging>pom</packaging>
<name>test</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.23</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
// src/main/resources/application.yml
test: 123