This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

BeanPostProcessor Problem with MVC @Controller

Feb 27th, 2012, 08:45 AM

Hi everyone,
i 've a problem with use of BeanPostProcessor in a @Controller component of my application. I've created a custom annotation (@MayaLog) to automatically instantiate org.apache.log4j.Logger in all bean. It works for all component (@Service, @Component) but don't works on @Controller.

Make sure your BeanPostProcessor is defined in the contexts you want it to operate on. If you define it only in the ContextLoaderListener and your Controllers are in the DispatcherServlet they aren't processed by that BeanPostProcessor (BPPs and BFPPs operate only on the factory/context they are defined in.).

Comment

I haven't found exactly how to solve the problem, but i did find a workaround, this might be useful for anyone having the same issue.
well instead of using a combination of BeanPostProcessor and a MetaDataScopeResolver, i decided to use a BeanFactoryPostProcessor that manages both the scope resolution and the bean processing. here'ds the code of the BeanFactoryPostProcessor for anyone interested:

Comment

First, thanks to all!!
I've found solution to problem. Thanks to Marten Deinum reply, i learn that DispatcherServlet (declared on web.xml) create a WebApplicationContext and due to this, the @Controller (i use org.springframework.web.servlet.mvc.support.Contro llerClassNameHandlerMapping for match web request url and controller) is instantiated inside this WebApplicationContext. Solution was to define in @Controller's relative configuration file my custom BeanPostProcessor. I hope, i was clear... thanks!!!!