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?
Asked
Active
Viewed 4,569 times
0

Kleber Mota
- 8,521
- 31
- 94
- 188
-
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 Answers
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
- 40,313
- 9
- 84
- 99