From your comment :
I would like to define dynamically beans based on command argument
values. Why to i do this in BeanFactoryPostProcessor - is to be sure
that bean definitions are there before actual bean instantiation- so i
don't need @DependsOn annotation.
In term of loading beans conditionally (like auto-configuration in spring boot), I would say that it's much cleaner to use the @ConditionalXXX annotations, most specifically the @ConditionalOnProperty.
Referencing the Java-doc for @ConditionalOnProperty
here they said :
Conditional that checks if the specified properties have a specific
value. By default the properties must be present in the Environment
and not equal to false. The havingValue() and matchIfMissing()
attributes allow further customizations.
So you can do something similar to :
@ConditionalOnProperty(prefix = "my.env", name = "var", havingValue = "true", matchIfMissing = false)