org.reflection.Reflections 0.10.2在作为jar运行时失败(例如在docker容器中)



我使用了org.reflections(最新(:

new Reflections("my.package").getSubTypesOf(MyService.class);

它在IntelliJ中运行良好,并返回MyService.class的所有实现。

但是在docker容器中运行时,它返回一个空的Set

(任何其他东西在码头集装箱中都能正常工作(

有什么想法吗?TIA!

这个答案来自注释

问题是以下错误/问题:

https://github.com/ronmamo/reflections/issues/373-"如果基类(或包前缀(作为参数传递,并且应用程序作为jar运行,则反射不会检测到任何类">

但它(对我来说(适用于上述问题中建议的变通方法。

Reflections reflections = new Reflections(new ConfigurationBuilder().forPackages("my.package"));
Set<Class<? extends MyService>> classes = reflections.getSubTypesOf(MyService.class);

最新更新