Integrate Swagger with JAVA + Maven + JDBC + Jersey for RESTful API documentation-Lab 2

Hi Readers,

I am happy to post another blog post on how to integrate swagger with RESTful API documentation with java.

You have created a RESTful project(say) and like to integrate swagger for representing your RESTful API then this post is for you.

I have done a maven project and will be listing out the dependencies and other settings to be done in your project to get the swagger representation.

You need to add some configuration tags and dependencies in web.xml and pom.xml . You can get those from this link.

In your service layer i.e REST layer of your project. You need to add @Api above the class and @ApiOperation above the method like this.

Now you need to integrate swagger ui into your projects.

Go to this link and download Swagger UI from github.

Unzip the swagger ui and go to dist folder(swagger-ui-2.2.6dist) and copy those files to your WebContent folder.

Your project will look like this


Once you have copied all the files from dist folder to your PROJECT/WebContent folder.

Open the index.html(swagger) and change the URL like below(line number 48)
url = “http://localhost:8080/YOURPROJECTNAME/URL PATTERN(check in web.xml file)/api-docs”; (i.e) url = “http://localhost:8080/SwaggerProjREST/rest/api-docs

Note: The above url should match with the web.xml swagger.api.basepath param value.

swagger.api.basepath http://localhost:8080/YOURPROJECTNAME/URL PATTERN

Now you have to build your project, you need to add maven dependencies to your deployment assembly of your project. Deploy the war in a tomcat server to get the below page.


If you get stuck, kindly comment below.

Ask me your questions/ doubt in quora.

Thanks for reading this post. Subscribe my blog for  some awesome posts.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s