Error creating bean with name ‘org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0’ defined in ServletContext resource

This is a limitation in Spring AOP. When you use AspectJ pointcuts to weave aspects into beans, Spring will use CGLIB to generate a subclass of the target, and invoke the aspects from that subclass.

If the target class does not have a public default constructor, however, this will fail. CGLIB does have the ability to handle this, but this is all hidden behind the Spring AOP stuff and you can’t change that behaviour.

I can only suggest that you go back to using setter injection for your controller, rather than constructor injection. It’s not ideal, I know, but I can’t think of any other workaround.

Leave a Comment