-
-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reflections doesn't return the list of classes annotated with RequestMapping #411
Comments
I was having a similar issue, Reflections wasn't able to find classes when running from docker. I bet it's caused due to the Java modules feature introduced in JDK 9, since Reflection scans with package names are working very well in our JDK8 projects. Using the following snippet, I was able to fix it, hope it helps: new Reflections(ConfigurationBuilder.build()
// Here we SET the URLs (no adding, to remove any eventually pre-setted but unnecessary URLs)
// using ClasspathHelper to get the URL for the given package
// For some reason, without this, scanning takes up to 20 seconds to finish
// and it scans a lot of classes (around 16k)
.setUrls(ClasspathHelper.forPackage(mainPackage))
.addScanners(TypesAnnotated)
// As people said in other issues, you need to explicitly set expandSuperTypes to false
// if you don't need it, or it may increase scanning time
.setExpandSuperTypes(false))
.get(TypesAnnotated.with(YourAnnotation.class).asClass()) Many thanks to @vlborkunov for his reply on #373, providing this solution. |
Thanks for the reply! I'm running in a container too. Anyhow, in the end I've decided to ditch the use of the Reflections library as it seems is not proactively maintained. Even the latest version being flagged as having some security issues. I've manage to get the same result with spring functionality. |
Amazing! Could I ask you to provide an example of how you did it? Just to serve as a source if someone comes across a similar problem in the future :) |
This is what I've done:
|
I'm trying to use reflections 0.10.2 in an open JDK 17 spring boot project to get the list of controller classes, but for some reasons I always get an empty list of classes.
This is how my code looks like:
A controller class looks like this:
All my controllers are under com.kp.mw.controllers and are annotated with @RequestMapping.
Any idea what is wrong here?
Thanks
The text was updated successfully, but these errors were encountered: