I try to build a native executable with GraalVM and Spring Boot 3.0.
When I use configuration properties class including a HashMap, starting of these application fails.
This class contains a simple map:
@Validated
@Data
@Component
@ConfigurationProperties(prefix = "test-props")
@FieldDefaults(level = AccessLevel.PRIVATE)
public class TestProperties {
@NotEmpty
HashMap<String, PermissionsConfig> datagroups;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public static class PermissionsConfig {
// fields
}
}
With configuration:
test-props:
datagroups:
data:
read:
code: READ_DATA
urlPattern:
- /some/pattern/
With this small test runner:
@Slf4j
@Component
@RequiredArgsConstructor
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public class TestRunner implements ApplicationRunner {
TestProperties testProperties;
@Override
public void run(ApplicationArguments args) throws Exception {
if (testProperties.getDatagroups() == null) {
throw new RuntimeException("property not binded");
}
log.info("property {}", testProperties);
}
}
Starting this as "normal" java application, everything works fine. As soon as I build the native executable I get following issue:
***************************
APPLICATION FAILED TO START
***************************
Description:
Binding to target org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'test-props' to test.properties.TestProperties failed:
Property: test-props.datagroups
Value: "null"
I also tried to add additional hints for the property class. Before adding these hints the validation didn't work at all.
I would expect that this would also work within a native image.
What have I overseen?
Steps to reproduce:
- get repo: https://github.com/sogmemu/HashMapInNativeBuild
- ./gradlew nativeCompile
- ./build/native/nativeCompile/app