code

@RestController
@SpringBootApplication
public class Boot3MpLogDemoApplication {

    private static final Logger logger = LoggerFactory.getLogger(Boot3MpLogDemoApplication.class);

    static ApplicationContext context;

    public static void main(String[] args) {
        context = SpringApplication.run(Boot3MpLogDemoApplication.class, args);
    }

    @GetMapping("/")
    public String hello(String name) {
        Map<String, TestService> beans = context.getBeansOfType(TestService.class);
        beans.forEach((beanName, bean) -> logger.info("beanName:{}, flag:{}", beanName, bean.getFlag()));
        return "hello world," + name;
    }

    @Bean
    public TestService bean1() {
        Boolean flag = true;
        bean2(flag);
        return new TestService();
    }

    @Bean
    public TestService bean2(Boolean flag) {
        TestService testService = new TestService();
        testService.setFlag(flag);
        return testService;
    }

    class TestService {
        private Boolean flag;

        public Boolean getFlag() {
            return flag;
        }

        public void setFlag(Boolean flag) {
            this.flag = flag;
        }
    }
}

Comment From: wilkinsona

Thanks for the report. Your bean definitions rely on bean2 being created as a side-effect of bean1 being created. This avoids the need for a Boolean bean but it is quite an unusual arrangement and isn't currently supported by Spring Framework's AOT processing. Note that the failure isn't specific to a native image. You will see the same failure if you run the application on the JVM with -Dspring.aot.enabled=true. If you would like the Spring Framework team to consider making a change here, please open a Spring Framework issue.