spring - How can I programatically add a beanPostProcessor to a ClassPathXmlApplicationContext? -


there's way programatically add beanpostprocessor classpathxmlapplicationcontext ?

i can declaratively in xml, apparently there's no way add programatically.

my processor must if bean myinterfaceaware, setmyinterface(...).

i need in code cause myinterface implementation instantiated in code, it's not available when starting xml.

i'm using spring 3.1.2.release.

thanks,

... i'm doing ...

public void setspringbeanfactory(beanfactory beanfactory) {     this.beanfactory = (applicationcontext) beanfactory;     ((classpathxmlapplicationcontext) beanfactory).getbeanfactory().addbeanpostprocessor(new beanpostprocessor() {          public object postprocessbeforeinitialization(object bean,                 string beanname) throws beansexception {             return bean;         }          public object postprocessafterinitialization(object bean,                 string beanname) throws beansexception {             if (bean instanceof registryaware)                 ((registryaware) bean).setregistry(applicationcontextregistryimpl.this);             return bean;         }     });     ((classpathxmlapplicationcontext)beanfactory).refresh(); } 

try context.getbeanfactory().addbeanpostprocessor(beanpostprocessor)

edit

you use beanfactorypostprocessor also:

public class registrybeanpostprocessorconfigurer implements beanfactorypostprocessor {      @override     public void postprocessbeanfactory(configurablelistablebeanfactory beanfactory) throws beansexception {         beanfactory.addbeanpostprocessor(getregistrybeanpostprocessor());     } }  context.addbeanfactorypostprocessor(new registrybeanpostprocessorconfigurer()); context.refresh(); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -