question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

Description 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:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

9reactions
viachmcommented, Feb 22, 2018

Had do downgrade org.reflections with some exclusions. Here is a pom.xml that worked for me:

<dependency>
    <groupId>org.reflections</groupId>
    <artifactId>reflections</artifactId>
    <version>0.9.10</version>
    <exclusions>
        <exclusion>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>annotations</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>com.smoketurner</groupId>
    <artifactId>dropwizard-swagger</artifactId>
    <version>1.1.2-1</version>
    <exclusions>
        <exclusion>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
        </exclusion>
    </exclusions>
</dependency>
8reactions
tyagiakhileshcommented, Feb 28, 2018

This works for me as well.

            <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-jaxrs</artifactId>
                <version>1.5.18</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.reflections</groupId>
                        <artifactId>reflections</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.reflections</groupId>
                <artifactId>reflections</artifactId>
                <version>0.9.10</version>
            </dependency>

Now, I am not sure if my App is problem or reflection is ? I guess reflection needs some reflection now… 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

newbie. problems in Swagger Set up - Google Groups
My project uses Spring so the hook up and configure& initialize I followed the spring section of the page. I put. <bean id="apiListingResource"...
Read more >
NoSuchMethodError: io.swagger.jaxrs.config.BeanConfig ...
I am working with CXF 3.1.8,i want to integrate Swagger,so i added the code below:
Read more >
io.swagger.jaxrs.config.BeanConfig Java Examples
This page shows Java code examples of io.swagger.jaxrs.config. ... this.register(SwaggerSerializers.class); BeanConfig config = new BeanConfig(); // config.
Read more >
BeanConfig (swagger-jaxrs 1.5.16 API) - javadoc.io
public class BeanConfig extends AbstractScanner implements Scanner, SwaggerConfig. Field Summary. Fields inherited from class io.swagger.jaxrs.config.
Read more >
io.swagger.jaxrs.config.BeanConfig java code examples
private void setupSwagger() { BeanConfig beanConfig = new BeanConfig(); beanConfig.setTitle("Pinot Broker API"); beanConfig.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found