spring-bootreflectionsjakarta-migration

Alternative supporting jakarta to `org.reflections:reflections` for finding annotated Methods


I am currently migrating to spring-boot 3. We use "org.reflections:reflections:0.10.2" in order to get all the classes in a package that contain a specific annotation (eg. RequestMapping.

  def requestMappingAnnotatedMethods() {
    Reflections reflections = new Reflections(
        new ConfigurationBuilder()
            .setUrls(ClasspathHelper.forPackage(rootPackage))
            .setScanners(new SubTypesScanner(), new MethodAnnotationsScanner()))
    return reflections.getMethodsAnnotatedWith(RequestMapping)
  }

Unfortunately the reflections lib is not maintained anymore and currently results in an Exception, as it is expecting javax instead of jakarta.

Any idea, what alternative we can use or how we can achieve the same behaviour without the lib?

copy/paste of the needed classes is of course possible, but I was hoping to get a better way of dong our task :)


Solution

  • As we discussed in comments solution can be approved answer(do it with ClassLoader) of this question, because Reflections library is currently NOT under active development or maintenance and last released is org.reflections:reflections:0.10.2 (Oct 2021).

    P.S. Also you have to upvote above linked solution.