Skip to main content

Quick Start:Swagger with Spring Boot

In this blog, we will go through how to create API documentation using swagger and spring boot.
Swagger is a framework for describing our API by using a common language that is an easy read and understand by developers and testers, even they have weak source code knowledge.
Following technologies stack being used:
  • Spring Boot 2.1.1.RELEASE
  • Spring 5.1.3.RELEASE 
  • Maven 3
  • JDK 1.8
  • Eclipse Oxygen
  • Swagger 2
1)Project Structure

2)Maven/Dependency Management [pom.xml] 
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
  <!-- lookup parent from repository -->
 <description>Demo project for springboot-swagger</description>
  <!-- spring mvc, rest -->
3)User Class
package com.knowledgefactory.knowledgefactorydemo;
public class User {
 private String id;
 private String name;
 private String mail;
 public String getId() {
  return id;
 public void setId(String id) { = id;
 public String getName() {
  return name;
 public void setName(String name) { = name;
 public String getMail() {
  return mail;
 public void setMail(String mail) {
  this.mail = mail;
 public User(String id, String name, String mail) {
  super(); = id; = name;
  this.mail = mail;
4)UserService Class
package com.knowledgefactory.knowledgefactorydemo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.stereotype.Service;
public class UserService {
 private List<User> topicList = new ArrayList<>(Arrays.asList(
   new User("1", "knowledgefactory", ""),
   new User("2", "Spring", ""), new User("3", "Java", "")
 public List<User> getTopicList() {
  return topicList;
 public void setTopicList(List<User> topicList) {
  this.topicList = topicList;
package com.knowledgefactory.knowledgefactorydemo;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
public class Controller {
 UserService service;
 @ApiOperation(value = "Find all User", notes = "Retrieving the collection of User", response = User[].class)
 @ApiResponses({ @ApiResponse(code = 200, message = "Success", response = User[].class) })
 public List<User> findAll() {
  return service.getTopicList();
6)Main Class
package com.knowledgefactory.knowledgefactorydemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
public class KnowledgefactorydemoApplication {
 public static void main(String[] args) {, args);
 public Docket swagger() {
  return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())


Popular posts from this blog

Spring boot video streaming example-HTML5

This article shows you how to stream MP4 video in Spring Boot web application 
User Interface

Project Structure

Home Controller
public class HomeController {
 private MyResourceHttpRequestHandler handler;
 private final static File MP4_FILE = new File("D:\\videofiles\\video1.mp4");
 // supports byte-range requests
 public String home() {
  return "index";
 // supports byte-range requests
 public void byterange( HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  request.setAttribute(MyResourceHttpRequestHandler.ATTR_FILE, MP4_FILE);
  handler.handleRequest(request, response);
Spring Boot 
@ComponentScan({ "com" })
public class KnowledgefactorydemoApplication {
 public static void main(String[] args) {, args);
MyResource HttpRequestHandler

DataTable-Pagination example with Spring boot,jQuery and ajax free download

This article shows you DataTable-Pagination example with Spring boot, jQuery and ajax. 

Following technologies stack being used:
Spring Boot 2.1.1.RELEASESpring 5.1.3.RELEASE Maven 3DatatablejQueryFree Markerjavascriptajax Project Structure
View(index.ftl) <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Knf|Pagination-Datatables</title> <!-- Tell the browser to be responsive to screen width --> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="../../css/jquery.dataTables.min.css"> <body>  <section class="content">   <div class="container-fluid">    <table id="example" class="display" style="width: 100%">     <thead>      <tr>       <th>First name</th>       <th>La…

9 Best Job Posting Sites for Employee 2020-2022

One of the most common ways today’s job seekers uncover employment opportunities are by using online sources. There are hundreds of job boards, both generic and niche, as well as aggregators, social media channels, networking groups, and staffing company websites to choose from. The good news is they provide plenty of listings. The bad news is you can be easily overwhelmed by so many options. Here, knowledge factory offers 9 of what is generally considered the best job search websites around. There are many others, of course, but this list of best job search websites should give you a good starting point for your next job hunt: 1. LinkedIn
This top networking site allows you to find jobs through your extended network. User profiles serve as resumes. You can easily share career-related content and solicit or supply recommendations. Additionally, you can join groups, participate in conversations, and follow companies you find interesting and relevant to your job search. Premium pai…