I have a requirement like below:
We have 20 Message Driven Beans in our application, when ever message has been arrived for each bean I need to log that information to database about the message. I can add this to each bean, but I need to change each and every class for each.
Is there a way where we can add some Filter class which will be fired before execution of MDB onMessage method. So that, I can have one class for logging all the MDB messages.
In general you should use some AOP technique. In detail, EJB provides an easy way to apply interceptors on MDBs:
Example taken from Configuring an Interceptor Class for an EJB 3.0 MDB.
To address your question from comment: you have access to
InvocationContextinside an interceptor which exposes all required attributes:Note that you can even alter the parameter or use a different one in interceptor.
You tagged your message with ejb-3.0 and spring. In Spring AOP options are much more flexible, but the general idea still applies.