79298823

Date: 2024-12-21 03:41:14
Score: 1
Natty:
Report link

Maybe method containsBeanDefinition from BeanDefinitionRegistry is what you're looking for.

Take a look over the documentation: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/factory/support/BeanDefinitionRegistry.html#containsBeanDefinition(java.lang.String).

You could specify the name of the bean and simply check if it returns false.

Example:

protected boolean isAlreadyRegistered(
          Class<?> clazz, 
          BeanDefinitionRegistry registry ) {
        return registry.containsBeanDefinition(clazz.getName());
}

P.S. there's a missing not (!) statement in your if.

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Mario MateaČ™