Configuring Swagger-core JAX-RS servlet less problem

1,238 views
Skip to first unread message

je...@ptmind.com

unread,
Sep 1, 2015, 11:56:05 PM9/1/15
to Swagger

Hi,


 I’m adding Swagger to an existing Java API code, using Jersey. It’s configured and I can access the swagger.json, but it doesn’t detect any resource,

Here's the code I use for configuration:


@Component
//Spring default path, uncomment to change
//@ApplicationPath("")
public class JerseyConfiguration extends ResourceConfig {

public JerseyConfiguration() {
super.packages("com.app.api");
super.register(ApiListingResource.class);
super.register(SwaggerSerializers.class);
//
//Swagger API definition
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.2");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath("/api");
beanConfig.setResourcePackage("io.swagger.resources");
beanConfig.setScan(true);
beanConfig.setPrettyPrint("true");
}
}


Here's what I get in the console


i.s.jaxrs.listing.ApiListingResource     : using scanner io.swagger.jaxrs.config.BeanConfig@1b670f24

org.reflections.Reflections              : given scan urls are empty. set urls in the configuration


I guess Swagger just doesn't know what to scan, but super.packages("com.app.api"); should be enough. 


How can I specify resources in this configuration?

PS: Swagger-maven-plugin works well and detects my resources.


Also, I'm confused by the Host and BasePath config": what are they for? Are they supposed to indicate an existing Swagger UI server where the API would be available?


thanks

Jean

Ron Ratovsky

unread,
Sep 3, 2015, 3:24:09 PM9/3/15
to Swagger
You need to set

      beanConfig.setResourcePackage("io.swagger.resources");

to your resources.

host is where you API is hosted (can be left empty).
basePath is the context root of your application.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

je...@ptmind.com

unread,
Sep 5, 2015, 1:04:37 AM9/5/15
to Swagger
Thanks a lot for pointing me at the right direction. This appears to be a very obvious mistake now, but it wasn't clear on the moment.
I've got everything working now, thanks to your numerous app sample.

Very good work!
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Sep 6, 2015, 5:21:03 AM9/6/15
to Swagger
Thank you for the feedback and confirmation. Glad you got it working.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages