Springfox integration to generate REST documentation

Hello,
we’re trying to integrate Springfox (http://springfox.github.io/springfox) in our Cuba projects, to generate RESTful documentation according to OpenAPI specification; our final objective is to generate a swagger.json to import in a Swagger environment (like WSO2 Api Manager).
Unfortunately, after lots of attempts, we’re stucked in this error at startup:

12:57:26.674 ERROR c.h.c.c.s.AbstractWebAppContextLoader - Error initializing application
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'documentationPluginsBootstrapper' defined in URL [jar:file:/D:/
workspace/test/rest-swagger-test/deploy/tomcat/shared/lib/springfox-spring-web-2.7.0.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstr
apper.class]: Unsatisfied dependency expressed through constructor parameter 6; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionExcept
ion: No qualifying bean of type 'javax.servlet.ServletContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations
: {}
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.3.10.RELEASE.jar:4.3
.10.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189) ~[spring-beans-4.3.10.RELEASE.jar:4.3
.10.RELEASE]

In attach to this post, a zip file with a sample (not working) project.

Could you please tell us where we’re wrong or provide a working example?

Thanks in advance for your support,

Regards,

Paolo

rest-swagger-test.zip (86.5 KB)

1 Like

Hi Paolo,

I’m not able to answer directly on what is the problem with your sprignfox setup but we plan to provide built in solution to expose Open API data.

2 Likes

Hi Vlad,
thank you very much for your kind reply.
I hope to see this useful functionality ASAP.
Bye,
Paolo

Hi,
you can find a sample with springfox here: GitHub - gorbunkov/sample-springfox: Sample project that shows how to include the Springfox

What I did there:

first, according to the CUBA doc, I created a custom oauth2 protected REST controller MyController.java and added the rest-dispatcher-spring.xml Spring configuration file.
Springfox is configured in this file. See the SwaggerConfig.java file.
Keep in mind that the URL for swagger json has been changed in the swagger.properties.
If you run the application, you’ll be able to get the swagger JSON by the URL http://localhost:8080/app/rest/swagger-api and Swagger-UI is available by the http://localhost:8080/app/rest/swagger-ui.html

3 Likes

Hi Max,
you are the man! :sunglasses:
It works well!

Thank you very much for your support.

Bye,
Paolo