Classloader issues?

58 views
Skip to first unread message

Simon Temple

unread,
Feb 20, 2015, 1:06:32 PM2/20/15
to swagger-sw...@googlegroups.com
Jetty 8, Jersey 2.6 and swagger-jersey2-jaxrs_2.10 1.3.12

I have a webapp that configures and starts jersey, registers a bunch of JAX-RS resources and configures swagger as per the instructions here: https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-2.X-Project-Setup

Unless the JAX-RS resources are defined in the same webapp they do not get included as an api by swagger.
I can see in the log that the reflection api is scanning many other JAR files:

2015-02-20 17:49:10,387 DEBUG [org.reflections.Reflections] (qtp2091910505-48) going to scan these urls:
<snip>
2015-02-20 17:49:10,533 INFO  [org.reflections.Reflections] (qtp2091910505-48) Reflections took 144 ms to scan 17 urls, producing 249 keys and 634 values  (Reflections.java:228)

Yet the only resources identified as "apis" are those in the current webapp classloader.

Can anyone help me identify if this is a webapp classloader issue? And if I can workaround it?

TIA

Simon

tony tam

unread,
Feb 20, 2015, 1:11:59 PM2/20/15
to swagger-sw...@googlegroups.com
If you want Swagger to scan anything outside of the webapp, you'll have to put them in your jetty/lib folder.  Per servlet spec, you don't get to access anything outside of the webapp unless it's in the parent classloader.

Simon Temple

unread,
Feb 23, 2015, 5:33:16 AM2/23/15
to swagger-sw...@googlegroups.com

Thanks Tony

My issue turned out to be that I had swagger-annotations loaded by multiple classloaders!

In DefaultJaxrsApiReader:
    val api = cls.getAnnotation(classOf[Api])
api was returning null.

Maybe calling cls.getAnnotations() and using the equality operator on Annotation could avoid this?

Anyway I excluded the annotation JAR from my webapp so all use the parent classloaded JAR  and it works fine.

tony tam

unread,
Mar 3, 2015, 8:31:45 PM3/3/15
to swagger-sw...@googlegroups.com
thanks for reporting back.  I think you'll end up with other issues with the multiple classloader issue so I'm glad you have it sorted out
Reply all
Reply to author
Forward
0 new messages