0

I have methods annotated as follows:

    @Action(actionType=<..>)
    public void doSomeAction() {
      ...
    }

Now, I would like to invoke one of such annotated methods with given actionType from another flow in another class.

In order to do this, I found the approaches as mentioned in the following SO posts:

  1. How to run all methods with a given annotation?
  2. Java seek a method with specific annotation and its annotation element

But in some cases, such methods may accept arguments as follows:

 @Action(actionType='SEND_NOTIFICATION')
 public void sendReport(String email) {
  ...
 }

In this regard, I am not able to understand, how to check if the annotated method has any params and invoke such methods with required params.

Joy
  • 4,197
  • 14
  • 61
  • 131
  • Once you have a `Method` object you can check what parameters it takes and provide them when you invoke it. – tgdavies Aug 12 '21 at 03:41
  • @tgdavies Thanks for your response. If possible, would you mind sharing, small code snippet for the same? – Joy Aug 12 '21 at 03:45
  • Is there a particular reason you can't just let Spring do this with `@EventListener`, or use Spring Integration if you need more granular setup? It's a solved problem. – chrylis -cautiouslyoptimistic- Aug 12 '21 at 03:46
  • @chrylis-cautiouslyoptimistic-Thanks. No there is no reason as such. Actually, I don't have much idea working with either EventListener or spring integration. – Joy Aug 12 '21 at 03:54
  • `Method m = ...; Class[] paramTypes = m.getParameterTypes(); m.invoke(theObject, params...);` but what are you actually trying to do, what's your environment? – tgdavies Aug 12 '21 at 03:56
  • @tgdavies Thanks. Actually, I am working on a spring boot application, wherein a given flow, I would like to invoke such function annotated with a specific value. – Joy Aug 12 '21 at 04:04
  • Use @EventListener then, and the individual event types can contain the parameters (so all the methods just take an event) – tgdavies Aug 12 '21 at 04:40

0 Answers0