spring Conditional bean registration in Spring


Important point to note while using condition

  • The condition class is referred as direct class (not as spring bean) so it can't use the @Value property injection i.e. no other spring beans can be injected within it.
  • From java docs - Conditions must follow the same restrictions as BeanFactoryPostProcessor and take care to never interact with bean instances. The restrictions refereed here are A BeanFactoryPostProcessor may interact with and modify bean definitions, but never bean instances. Doing so may cause premature bean instantiation, violating the container and causing unintended side-effects.