Я пытаюсь активировать что-то вроде этого из файла YML
System.out.println("US City====>"+addressProperties.getFromaddress().get("US").getCity());
System.out.println("US City====>"+addressProperties.getFromaddress().get("US").getCountry());
System.out.println("US City====>"+addressProperties.getFromaddress().get("US").getPostalCode());
System.out.println("DE City====>"+addressProperties.getFromaddress().get("DE").getCity());
System.out.println("DE City====>"+addressProperties.getFromaddress().get("DE").getCountry());
System.out.println("DE City====>"+addressProperties.getFromaddress().get("DE").getPostalCode());
У меня есть содержимое файла yaml, как показано ниже
address:
fromaddress:
US:
country: US
city: New York
postalcode: 44444
region: NY
DE:
country: DE
city: Munich
postalcode: 33333
region: BE
:
:
:
:
Я создал DTO длявышеупомянутое содержание ямс, как показано ниже
@Data
public abstract class AddressProperties extends HashMap<String, FromAddress> {
}
@Data
@Builder
public class FromAddress
{
private String country;
private String city;
private String postal;
private String region;
}
@Data
@ConfigurationProperties(prefix = ”address”)
@Service
public class FromAddressProperties
{
public AddressProperties fromaddress;
}
Но я получаю следующее исключение
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘addressService' defined in file [/Users/xxxx/xxxx/workspaces/xxxx/target/classes/com/xxx/liita/xxxx/services/AddressService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘fromAddressProperties': Could not bind properties to FromAddressProperties (prefix=address, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'fromaddress[US]' of bean class [com.xxx.xxx.xxx.xxx.AddressProperties]: Illegal attempt to get property 'fromaddress' threw exception; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property 'fromaddress' of bean class [com.xxx.xxx.xxx.xxx.FromAddressProperties]: Could not instantiate property type [com.xxx.xxx.xxx.xxx.FromAddressProperties] to auto-grow nested property path; nested exception is java.lang.IllegalArgumentException: Could not instantiate Map type: com.xxx.xxx.xxx.domains.FromAddressProperties
Недопустимое свойство 'fromaddress [US]' класса bean [com.xxx.xxx.xxx.xxx.AddressProperties]: незаконная попытка получить свойство 'fromaddress' вызвала исключение
Может кто-нибудь, пожалуйста, помогите мне в этом, например, узнать, где я ошибся
ОБНОВЛЕНИЕ 1
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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xxxxx</groupId>
<artifactId>xxxx-xxxxxx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>xxx-xxxxx</name>
<description>Sample Test</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>