spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.51k stars 598 forks source link

Resolve startup warning log when integrating with SpringBoot #1156

Open ilxqx opened 1 month ago

ilxqx commented 1 month ago

Have the following warning log when starting:

2024-05-28T11:26:03.392+08:00  WARN 74763 --- [state-machine] [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.statemachine.config.configuration.StateMachineAnnotationPostProcessorConfiguration' of type [org.springframework.statemachine.config.configuration.StateMachineAnnotationPostProcessorConfiguration$$SpringCGLIB$$0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). The currently created BeanPostProcessor [org.springframework.statemachine.processor.stateMachineAnnotationPostProcessor] is declared through a non-static factory method on that class; consider declaring it as static instead.

A possible solution:

Original code:

@Configuration
public class StateMachineAnnotationPostProcessorConfiguration {

    private final static String POST_PROCESSOR_BEAN_ID = "org.springframework.statemachine.processor.stateMachineAnnotationPostProcessor";

    @Bean(name = POST_PROCESSOR_BEAN_ID)
    public StateMachineAnnotationPostProcessor springStateMachineAnnotationPostProcessor() {
        return new StateMachineAnnotationPostProcessor();
    }

}

New code:

public class StateMachineAnnotationPostProcessorConfiguration {

    private final static String POST_PROCESSOR_BEAN_ID = "org.springframework.statemachine.processor.stateMachineAnnotationPostProcessor";

    @Bean(name = POST_PROCESSOR_BEAN_ID)
    public static StateMachineAnnotationPostProcessor springStateMachineAnnotationPostProcessor() {
        return new StateMachineAnnotationPostProcessor();
    }

}

SpringBoot considers StateMachineAnnotationPostProcessor as a PostProcessor. The creation of this bean necessitates the prior instantiation of the StateMachineAnnotationPostProcessorConfiguration class. However, the instantiation of this class further requires all PostProcessors to process it, including StateMachineAnnotationPostProcessor. Consequently, this results in a warning log indicating that some PostProcessors cannot process it. While it's true that the StateMachineAnnotationPostProcessorConfiguration class does not actually require any PostProcessor processing, SpringBoot is not intelligent enough to discern this. Though this warning is rather harmless, it can be somewhat bothersome to individuals with OCD😄.