spring - Restrict bean creation count -
is there way restrict number of beans created in application using spring?.
i tried seeing applicationcontextaware , beansfactoryutil. beansfactoryutils has method called countbeansincludingancestors() doesnt let me know if bean of particular type , on.
any appreciable.
i guess want restrict number of bean definitions. use beanfactorypostprocessor
check it
public class maximumbeandefinitionspostprocessor implements beanfactorypostprocessor { private int maximum = 100; @override public void postprocessbeanfactory( configurablelistablebeanfactory beanfactory) throws beansexception { if (beanfactoryutils.countbeansincludingancestors(beanfactory) > this.maximum) throw new beandefinitionstoreexception("maximun number of bean defintions execeeded [" + maximum + "]"); } }