I'm using the @Controller annotation for my controller components to have them auto-scanned as beans. Works fine until I get to classes that implement other interfaces (i.e. non-controller interfaces). For example:Code:
@Controller
@RequestMapping(quot;/addUser.htmquot;)
public class AddUserController implements ApplicationEventPublisherAware {
The above gives me the following error when I navigate to addUser.htm:Code:
No adapter for handler [my.controllers.AddUserController@8d3d62]: Does your handler implement a supported interface like Controller?
It works fine if I remove the implementation of the ApplicationEvent class.
Is there a limitation that annotated controllers can't implement other interfaces? Or did I need to do something more (I have the ApplicationEventPublisherAware required method (setApplicationEventPublisher) annotated with @Override, but that's all).
Spring uses proxies for aop, by default this are JDK DynamicProxies. It creates a dynamic class which implements your interface, so you get a new class which is a 'ApplicationEventPublisherAware' but which isn't a @Controller anymore because the annotation is on the wrapped class.
This should be fixed in spring 3, however you could switch to classproxying instead of interface based proxies, this adds a dependecy on cglib.
I still see the same effect in 3.0.4. I added ServletContextAware to my @Controller class, and got that lovely error:
javax.servlet.ServletException: No adapter for handler [com.bc.intl.web.admin.AdminController@bf21bf]: Does your handler implement a supported interface like Controller?
Ha, but in this particular instance you can use this in your @Controller:
@Autowired
private ServletContext servletContext; |