Question Details

No question body available.

Tags

spring spring-boot

Answers (1)

March 12, 2026 Score: 0 Rep: 775 Quality: Low Completeness: 60%

Spring Boot's Environment flattens map properties (e.g., test.map-property.foo=1). Because there is no single "Map" object in the source environment to pass to your Converter, Spring Boot falls back to the MapBinder to aggregate the keys.

To aggregate, MapBinder tries to instantiate your target type (ImmutableMap) via reflection using CollectionFactory.createMap(). This throws an exception because ImmutableMap is an abstract class without a default constructor.

Might let Spring Boot bind to standard Java Collections, and then immediately transform them in an overloaded record constructor.

import org.springframework.boot.context.properties.bind.ConstructorBinding;

@ConfigurationProperties("test") public record ApplicationProperties( ImmutableList listProperty, ImmutableSet setProperty, ImmutableMap mapProperty ) {

// Tell Spring Boot to use this specific constructor for binding @ConstructorBinding public ApplicationProperties( List listProperty, Set setProperty, Map mapProperty) {

// Delegate to the canonical constructor with immutable copies this( listProperty == null ? ImmutableList.of() : ImmutableList.copyOf(listProperty), setProperty == null ? ImmutableSet.of() : ImmutableSet.copyOf(setProperty), mapProperty == null ? ImmutableMap.of() : ImmutableMap.copyOf(mapProperty) ); } }