Spring boot 3.2.1 apps including Web-Mvc and Spring security dependency crash in autoconfiguration after building native image with duplicate bean registration of mvcHandlerMappingIntrospector - see log excerpt below.
Used:
Java version: 17.0.9+11-LTS, vendor version: Liberica-NIK-23.0.2-1
[INFO] [creator] Graal compiler: optimization level: 2, target machine: armv8-a
[INFO] [creator] C compiler: gcc (linux, aarch64, 11.4.0)
JVM-started app with Spring Boot 3.2.1 as well as Native image (same Java, Graal, C) with Spring 3.2.0 works fine.
w.s.c.ServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'mvcHandlerMappingIntrospectorRequestTransformer' defined in null: Cannot register bean definition < ..omitted..>
APPLICATION FAILED TO START
Description: The bean 'mvcHandlerMappingIntrospectorRequestTransformer' could not be registered. A bean with that name has already been defined and overriding is disabled.
To reproduce it suffices to add Web-MVC and security starter dependency and just one get-endpoint (see example-repo https://github.com/wisskirchenj/example-native
My suspicion is a duplicate bean registration in AOT processing, as the generated source file
target/spring-aot/main/sources/org/example/ExampleApplication__BeanFactoryRegistrations.java
contains the lines:
beanFactory.registerBeanDefinition("mvcHandlerMappingIntrospector", WebMvcConfigurationSupport__BeanDefinitions.getMvcHandlerMappingIntrospectorBeanDefinition()); // l.156
beanFactory.registerBeanDefinition("mvcHandlerMappingIntrospectorRequestTransformer", HandlerMappingIntrospectorRequestTransformer__BeanDefinitions.getMvcHandlerMappingIntrospectorRequestTransformerBeanDefinition()); // l.253
and the second line is not present, when doing spring-boot:process-aot with version 3.2.0.
EDIT: I saw now, that the class HandlerMappingIntrospectorRequestTransformer has been added recently in Spring security 6.2.1.
Comment From: wisskirchenj
Oops - just saw, it's a dup of issue #38910. Sorry - I close this issue