t77*_*777 5 java spring reflections docker spring-boot
我使用了 org.reflections (最新):
new Reflections("my.package").getSubTypesOf(MyService.class);
Run Code Online (Sandbox Code Playgroud)
它在 IntelliJ 中运行良好,并返回MyService.class.
但在 docker 容器中运行时,它返回一个空的Set.
(其他任何东西都可以在 docker-container 中正常运行)
有任何想法吗?蒂亚!
t77*_*777 10
这个答案来自评论......
问题是以下错误/问题:
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);
Run Code Online (Sandbox Code Playgroud)