Archive by Author | jananidhanween

Swagger – Spring Boot

Step #1: Add maven dependency

                <dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.6.1</version>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.6.1</version>
		</dependency>

Step #2: Create a SwaggerConfig.java in com.janani.config

package com.revature.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

	@Bean
	public Docket api() {
		// @formatter:off
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("lms-api")
				.apiInfo(apiInfo())
				.select()
				.paths(PathSelectors.any()).build();
	}

	// @formatter:on
	// private Predicate<String> fetchPaths() {
	// return or(regex("/holidays.*"), regex("/roles.*"),
	// regex("/employees.*"));
	// }

	private ApiInfo apiInfo() {
		// @formatter:off
		return new ApiInfoBuilder()
				.title("LMS API")
				.description("Leave Management System")
				.license("LMS License")
				.contact("jananise@gmail.com")
				.licenseUrl("https://github.com/JananiVelmurugan")
				.version("1.0").build();
	}

}

Step #3: http://localhost:5000/swagger-ui.html#/

Notes

Spring 01 – Introduction

Spring Framework – Overcome tightly-coupled
Dependency of Injection – Inversion of Control
Install Spring Framework (Two ways)
-> Dependency Management Tool – Maven downloads spring jars from central repository
-> download jars directly
Spring project recommends 1st way
Java Beans or Beans

Log4 j
Library for logging functionality
Speed and thread safety
Allows to set different logging levels
Download log 4 j
https://logging.apache.org/log4j/2.x/download.html
Levels
ALL<DEBUG<INFO<WARN<ERROR where advice is actually applied
Aspect = Advice + Pointcut
Introduct/Mixin -> introduce new methods to a class
Weaving – process of creating proxies
4 main components
 Application context
 A configuration class
 The beans
 Aspect that advice beans

Demo on $scope

<html ng-app="myApp">

<head>
    <script src="angular.min.js"></script>
    <script>
        var productApp = angular.module("myApp", []);
        console.log("myApp called");
        productApp.controller("myController", function ($scope) {
            console.log("myController called");
            $scope.showProducts = function () {
                console.log("showProducts called");
                $scope.products = ["Samsung", "Apple"];
                console.log($scope.products);
            }
        });
    </script>
</head>

<body>
    <div ng-controller="myController">
        <a href="#" ng-click="showProducts()">Show Products</a> {{products}}
    </div>
</body>

</html>

First Controller

<html ng-app="myApp">

<head>
    <script src="angular.min.js"></script>
    <script>
        var myFirstApp = angular.module('myApp', []);
        myFirstApp.controller("FirstController", function () {
            console.log("FirstController Called");
        });
    </script>
</head>

<body>
    <div ng-controller="FirstController">
        Welcome to ng
</body>

</html>

First Module

<html ng-app="myApp">

<head>
    <script src="angular.min.js"></script>
    <script>
        var myFirstApp = angular.module('myApp', []);
        console.log("Hello World");
    </script>
</head>

<body>
    Welcome to ng
</body>

</html>

Hello World

<html ng-app="myFirstApp">
<head>
    <script src="angular.min.js"></script>
    <script>
        console.log("Hello World");
    </script>
</head>
<body>
        Welcome to ng 
</body>
</html>