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
.