0

In my current spring project, I need read in my service class all classes with a specific custom annotation (@MainForm) and return a List> to the controller. The class which should be read are placed on the package com.spring.loja.model. Anyone knows a way to do that?

Kleber Mota
  • 8,111
  • 29
  • 86
  • 174
  • I would recommend annotation processing. – emory Aug 18 '14 at 00:50
  • If you configure your application using the spring framework, it's easy to get all beans with a certain annotation. Read this blog post: https://web.archive.org/web/20141216203709/http://techo-ecco.com/blog/spring-custom-annotations/ – Erwin Bolwidt Aug 18 '14 at 01:21

1 Answers1

0

You can use isAnnotationPresent() reflection method

  // Get all classes
  List<Class> klasses = ..

  // Filter only those containing
  for(Class k : klasses) {
    if(k.isAnnotationPresent(MainForm.class)) ...
  }
gerrytan
  • 38,987
  • 8
  • 81
  • 96