swagger-jaxrs io.swagger.jaxrs.config.BeanConfig.setScan() throws exception in reflection of ehcache library and classes when running via -all.jar as classes are missing
See original GitHub issueDescription If you init Swagger using BeanConfig.setScan(true) (see: https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/config/BeanConfig.java#L220) it will throw many exceptions in case you are using generated Beans as response objects.
See exception below. It fails on those classes as it seems they are .classes_terracotta
The issue is that certain classes are not packaged into the -all jar. I can unpack the -all jar and indeed classes are missing that are referenced in the project classpath.
Versions: swagger-core version 1.5.13 (I also tried 1.5.17, had same issue, but slight different stack trace) ehcache version is 2.10.3 CXF version is 3.1.9
Ehcache: This error happens every time scan is invoked.
It obviously has something to do with the way the ehcache library is using some overwrite within their rest-management-private-classpath package.
However ehcache is a common library for caching and often you can’t really prevent it. In the case of CXF if comes automatically, there is no way to exclude it.
Exception when doing BeanConfig.setScan(true):
2017-12-22 10:27:01,759 14438 WARN [main] [] o.r.Reflections - could not get type for name net.sf.ehcache.management.resource.services.CachesResourceServiceImpl from any class loader
org.reflections.ReflectionsException: could not get type for name net.sf.ehcache.management.resource.services.CachesResourceServiceImpl
at org.reflections.ReflectionUtils.forName(ReflectionUtils.java:390)
at org.reflections.ReflectionUtils.forNames(ReflectionUtils.java:409)
at org.reflections.Reflections.getTypesAnnotatedWith(Reflections.java:433)
at org.reflections.Reflections.getTypesAnnotatedWith(Reflections.java:418)
at io.swagger.jaxrs.config.BeanConfig.classes(BeanConfig.java:277)
at io.swagger.jaxrs.config.BeanConfig.scanAndRead(BeanConfig.java:240)
at io.swagger.jaxrs.config.BeanConfig.setScan(BeanConfig.java:221)
at my.company.myproject.myapi.MyapiApplication.swagger(MyapiApplication.java:115)
at my.company.myproject.myapi.MyapiApplication.run(MyapiApplication.java:70)
at my.company.myproject.myapi.MyapiApplication.run(MyapiApplication.java:30)
at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:43)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:85)
at io.dropwizard.cli.Cli.run(Cli.java:74)
at io.dropwizard.Application.run(Application.java:89)
at my.company.myproject.myapi.MyapiApplication.main(MyapiApplication.java:38)
Caused by: java.lang.ClassNotFoundException: net.sf.ehcache.management.resource.services.CachesResourceServiceImpl
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.reflections.ReflectionUtils.forName(ReflectionUtils.java:388)
... 14 common frames omitted
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.reflections.ReflectionUtils.forName(ReflectionUtils.java:388)
... 14 common frames omitted
Issue Analytics
- State:
- Created 6 years ago
- Comments:9
Top GitHub Comments
Had do downgrade org.reflections with some exclusions. Here is a pom.xml that worked for me:
This works for me as well.
Now, I am not sure if my App is problem or reflection is ? I guess
reflection
needs some reflection now… 😃