I am trying to migrate from Spring 2.0 to Spring 3.0.
Previously I defined a controller MyController
inheriting from SimpleFormController
and have some logic written in the onSubmit
method. All my controllers having the handler methods are inherited from MyController
. Thus, the logic written in onSubmit
of MyController
used to get executed for all requests.
Now as I migrate to annotated controller wherein my controller is a simple pojo, how do I ensure the execution of onSubmit
everytime? One way is to call onSubmit
from all handler methods of all the controllers. This is cumbersome.
Can anyone suggest any feasible solution. As annotating formBackingObject
with @ModelAttribute
ensures the invocation for all requests, isn't there an analogy for onSubmit
method?
If you want to perform the same action before each invokation of any annotated controller, you could use an interceptor. You can write your own interceptor by just implementing the preHandle method. You will then need to register this interceptor in the DefaultAnnotationHandlerMapping or whatever Handler mapping you use to dispatch to your controllers. Registering interceptors is explained in this article: http://www.scottmurphy.info/spring_framework_annotation_based_controller_interceptors
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With