Skip to content

Make spring-analyzer bean post processor distinguish 3 kinds of beans: @Component-like beans, @Bean-like beans, and XML-like beans#2178

Merged
EgorkaKulikov merged 1 commit intomainfrom
ilya_m/spring_rewrite_bean_class_name
Apr 25, 2023
Merged

Make spring-analyzer bean post processor distinguish 3 kinds of beans: @Component-like beans, @Bean-like beans, and XML-like beans#2178
EgorkaKulikov merged 1 commit intomainfrom
ilya_m/spring_rewrite_bean_class_name

Conversation

@IlyaMuravjov
Copy link
Collaborator

Description

Make it so 3 main kinds of beans are treated separately when it comes to determining their type:

  • For @Component-like beans we can get the type by simply looking at the annotated class
  • For @Bean-like beans we have to analyze the method defining bean (for now, we actually run it)
  • For XML-like beans we can use beanClassName

This pull request is relevant because the approach used earlier failed for @Bean-like beans defined with a static method. It returned type of the @Configuration class defining the bean instead of type of the bean itself . For instance, in the following example for bean beanLogBeanFactoryPostProcessor we got WebConfiguration as its type instead of LogBeanFactoryPostProcessor.

@Configuration
public class WebConfiguration {
    @Bean
    public static LogBeanFactoryPostProcessor beanLogBeanFactoryPostProcessor() {
        return new LogBeanFactoryPostProcessor();
    }
}

How to test

Manual tests

Generate tests for Spring projects using all 3 kinds of beans.

Self-check list

  • I've set the proper labels for my PR (at least, for category and component).
  • PR title and description are clear and intelligible.
  • I've added enough comments to my code, particularly in hard-to-understand areas.
  • The functionality I've repaired, changed or added is covered with automated tests.
  • Manual tests have been provided optionally.
  • The documentation for the functionality I've been working on is up-to-date.

@IlyaMuravjov IlyaMuravjov added ctg-enhancement New feature, improvement or change request comp-spring Issue is related to Spring projects support labels Apr 24, 2023
@EgorkaKulikov EgorkaKulikov merged commit a072f62 into main Apr 25, 2023
@EgorkaKulikov EgorkaKulikov deleted the ilya_m/spring_rewrite_bean_class_name branch April 25, 2023 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-spring Issue is related to Spring projects support ctg-enhancement New feature, improvement or change request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants