title: Java-Reflection - find the Arguments and the annotation before the method
body: <p>I am able to get the class and it's method name when for given package name. the code is below :</p>
  
  <pre><code>package com.hexgen.reflection;
  
  import java.lang.reflect.Method;
  import java.util.Iterator;
  import java.util.List;
  
  import org.springframework.web.bind.annotation.RequestMapping;
  
  import com.hexgen.ro.request.CreateRequisitionRO;
  import com.hexgen.tools.HexgenClassUtils;
  
  public class HexgenWebAPITest {
  
  
      @SuppressWarnings({ "rawtypes", "unchecked", "unused" })
      public static void main(String[] args) {
          HexgenWebAPITest test = new HexgenWebAPITest();
          HexgenClassUtils hexgenClassUtils = new HexgenClassUtils();
          String uri="";
          String[] mappingValues=null;
          HttpClientRequests httpRequest = new HttpClientRequests();
          Class parames = CreateRequisitionRO[].class;
  
          Class booleanVal;
          booleanVal = Boolean.TYPE;
          Class cls;
  
  
          try {
              List classNames = hexgenClassUtils.findMyTypes("com.hexgen.*");
              Iterator&lt;Class&gt; it = classNames.iterator();
              while(it.hasNext())
              {
  
                  Class obj = it.next(); 
                  System.out.println("Methods available in : "+obj.getName());
                  System.out.println("===================================");
                  cls = Class.forName(obj.getName());
                  Method[] method = cls.getMethods();
                  int i=1;
                  for (Method method2 : method) {
                      System.out.println(+i+":"+method2.getName());
                      i++;
                  }
                  System.out.println("===================================");
              }
  
  
          } catch (Exception ex) {
              ex.printStackTrace();
          }
  
      }
  
  }
  </code></pre>
  
  <p>and the following is my util class : </p>
  
  <pre><code>package com.hexgen.tools;
  
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.springframework.core.io.Resource;
  import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
  import org.springframework.core.io.support.ResourcePatternResolver;
  import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
  import org.springframework.core.type.classreading.MetadataReader;
  import org.springframework.core.type.classreading.MetadataReaderFactory;
  import org.springframework.stereotype.Controller;
  import org.springframework.util.ClassUtils;
  import org.springframework.util.SystemPropertyUtils;
  
  public class HexgenClassUtils {
      @SuppressWarnings({ "rawtypes", "unused" })
      public List&lt;Class&gt; findMyTypes(String basePackage) throws IOException, ClassNotFoundException
      {
          ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
          MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
  
          List&lt;Class&gt; candidates = new ArrayList&lt;Class&gt;();
          String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
                                     resolveBasePackage(basePackage) + "/" + "**/*.class";
          Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
          for (Resource resource : resources) {
              if (resource.isReadable()) {
                  MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                  if (isCandidate(metadataReader)) {
                      candidates.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
                  }
              }
          }
          return candidates;
      }
      public String resolveBasePackage(String basePackage) {
          return ClassUtils.convertClassNameToResourcePath(SystemPropertyUtils.resolvePlaceholders(basePackage));
      }
  
      @SuppressWarnings({ "rawtypes", "unchecked" })
      public boolean isCandidate(MetadataReader metadataReader) throws ClassNotFoundException
      {
          try {
              Class c = Class.forName(metadataReader.getClassMetadata().getClassName());
              if (!c.isInterface() &amp;&amp; c.getAnnotation(Controller.class) != null) {
                  return true;
              }
          }
          catch(Throwable e){
          }
          return false;
      }
  
  }
  
  now how can i get the methods arguments and it's type through programmatically in spring ?
  </code></pre>
  
  <p>take for example, if i get the class and the following method in it, then one should be able to get <code>@PreAuthorize,@RequestMapping,@ResponseBody,methodName and arguments it has like in this case it would be RequestBody CreateRequisitionRO[] request,
                  @RequestHeader("validateOnly") boolean validateOnly and their TYPE</code></p>
  
  <pre><code>@PreAuthorize("isAuthenticated() and hasPermission(#request, 'CREATE_REQUISITION')")
      @RequestMapping(method = RequestMethod.POST, value = "/trade/createrequisition")
      public @ResponseBody
      void createRequisition(@RequestBody CreateRequisitionRO[] request,
              @RequestHeader("validateOnly") boolean validateOnly) {
          logger.debug("Starting createRequisition()...");
          for (int i = 0; i &lt; request.length; i++) {
              CreateRequisitionRO requisitionRequest = request[i];
  
              // FIXME this has to be removed/moved
              requisitionRequest.setFundManager(requisitionRequest.getUserId());
              // FIXME might have to search using param level as well
              SystemDefault sysDefault = dbFuncs.references.systemDefault
                      .findByCompanyAndDivisionAndPortfolio(
                              userContext.getCompany(),
                              userContext.getDivision(),
                              requisitionRequest.getPortfolio());
              requisitionRequest.setCustodianN(sysDefault.getCustodianN());
  
              gateKeeper.route(requisitionRequest);
          }
      }
  </code></pre>
  
  <p>Please help me to resolve this.</p>
  
  <p>Best Regards</p>