I work on spring boot version: 2.0.2.RELEASE. In my application.yml I have:
cars:
color-to-brands:
red: car1, car2
blue: car3, car4
and my config class looks like this:
@Getter @Setter
@Configuration
@ConfigurationProperties(prefix = "cars")
public class CarsProperties {
private Map<String, List<String>> colorToBrands = Collections.emptyMap();
}
When I start the app, I'm keep getting:
Failed to bind properties under 'cars.color-to-brands' to java.util.Map>:
Reason: Failed to bind properties under 'cars.color-to-brands' to java.util.Map<java.lang.String, java.util.List<java.lang.String>>Action:
Update your application's configuration
Now, to summarize what I have already done to fix it:
- According to documentation I have added a dependency that gives
me annotation processor for my
@ConfigurationProperties:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <version>${spring-boot.version}</version> <optional>true</optional> </dependency>
I have annotation processor enabled. I'm using Intellij.
Annotation processors->Maven default annotation processors profilehas tickedEnable annotation processing,Processor path:contains(...)\.m2\repository\org\springframework\boot\spring-boot-configuration-processor\2.0.2.RELEASE\spring-boot-configuration-processor-2.0.2.RELEASE.jar,Store generated sources relative to: Module content root,In the pom file I've added path for this processor (among others I use):
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>1.8</source> <target>1.8</target> <annotationProcessorPaths> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </path> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${mapstruct.version}</version> </path> <path> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <version>${spring-boot.version}</version> </path> </annotationProcessorPaths> <compilerArgs> <compilerArg> -Amapstruct.defaultComponentModel=spring </compilerArg> </compilerArgs> </configuration>
- In addition, intellij keep showing me a popup inside the
CarsProperties:
Re-run Spring Boot Configuration Annotation Processor to update generated metadata
- I've skipped
@EnableConfigurationPropertiesas:
Spring Boot documentation says, every project automatically includes @EnableConfigurationProperties.
- Somewhere in between I also did:
Reimport All Maven Projects,clean install,Rebuild project, andInvalid Caches and Restart
I'm sitting in front of that computer for few hours now, Can't get it done. What am I doing wrong ? Why it doesn't want to work ?