2021 Edition - A Java Spring Boot Microservices Project for Beginners | Engineering Tech | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

2021 Edition - A Java Spring Boot Microservices Project for Beginners

teacher avatar Engineering Tech, Big Data, Cloud and AI Solution Architec

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

56 Lessons (4h 8m)
    • 1. Introduction

    • 2. Rest Web Service

    • 3. Understanding microservices

    • 4. Microservices learning path

    • 5. Installing JDK

    • 6. Installing IntelliJ

    • 7. Java hello world

    • 8. Java data types and variables

    • 9. Java operators

    • 10. Java control flow statements

    • 11. Importing a Java project into IntelliJ

    • 12. Java class and object

    • 13. Java inheritence

    • 14. Java interface

    • 15. Java package

    • 16. Java method overloading

    • 17. Java constructor

    • 18. Java this keyword

    • 19. Java access modifiers

    • 20. POJO, Java Bean and Serialization

    • 21. Java dynamic polymorphism

    • 22. Injecting an object

    • 23. Annotation annotation annotation

    • 24. Spring Framework and Spring Boot Introduction

    • 25. A Hello World REST service using Spring Boot

    • 26. Dependency Injection Using Spring Framework

    • 27. Maven for build and dependency management

    • 28. IntelliJ Quick Tip - Maven Reimport

    • 29. Creating a Spring Boot application with multiple dependencies

    • 30. Returning an object to REST API

    • 31. JPA, ORM , Hibernate and Spring Data JPA

    • 32. Installing a SQLite Database

    • 33. Fetching data from database using Spring Data JPA

    • 34. Spring Boot Advantages

    • 35. Postman REST Client

    • 36. CRUD operations using Spring Data JPA

    • 37. Exporting the Application to a JAR File

    • 38. Integrating services with RestTemplate

    • 39. Service Discovery

    • 40. Setting up a Eureka Discovery Server

    • 41. Registering the Course app as a Eureka client

    • 42. Integrating the Course Catalog app with the Course app through the Eureka server

    • 43. What happens when the Course app goes down?

    • 44. Handling failure with Circuit Breaker

    • 45. Implementing Circuit Breaker with Netflix Hystrix

    • 46. Course Catalog Project - Problem Statement

    • 47. Building the User App

    • 48. Querying the User App on a specific field in the User table

    • 49. Enhancing the Course Catalog App to fetch data from the User App

    • 50. Why externalize Configuration properties?

    • 51. Setting up a Spring Cloud Config Server with Git

    • 52. Reading configuration from application.properties

    • 53. Integrating Microservices with Spring Cloud Config Server

    • 54. Refreshing configuration without restarting microservices

    • 55. Dynamic Routing using Netflix Zuul

    • 56. Client side load balancing using Netflix Ribbon

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

Learn to build a Java Spring Boot Micro-services application with Spring Cloud. You will learn the following modules with hands on examples.

1. Java Basics

2. Spring Framework

3. Spring Boot

4. Spring Data JPA

5. Spring Cloud

5. IntelliJ Idea, Maven

6. Microservices

Build the application from scratch with step by step instructions.

No prior Java or Spring knowledge required. Basic programming skills and database knowledge required to get started

What you’ll learn

  • Java Spring Boot Microservices from scratch with hands on examples
  • Spring Cloud

Are there any course requirements or prerequisites?

  • Basic programming skills and Database knowledge required

Who this course is for:

  • Java beginners
  • Micro services beginners

Meet Your Teacher

Teacher Profile Image

Engineering Tech

Big Data, Cloud and AI Solution Architec


Hello, I'm Engineering.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Introduction: Welcome to this Java springboard microservices course for absolute beginners. This is going to be an exciting journey. You'll be starting with a simple HelloWorld program. And by the time you finish this course, you will feel confident about building Martin enterprise applications. Taking it microservices based approach. Step-by-step. You lawn service discovery, how to handle failure, dynamic routing, API Gateway and various other concepts of microservices. Trying out things yourself. You'll apply all your learnings to build a course catalog from scratch. Taking a microservices based approach. You do not need to have a knee pad backbone in Java, Spring framework God springboard before starting with this course. Also, no prior knowledge of microservices required. All you need is some basic programming skills and prior knowledge of database Sequel queries to succeed in this course. So let's dive in and get started. 2. Rest Web Service: Before we dive into microservices, let's understand service or web service in the internet world. Web service is a software that makes it available over the Internet. A web service can be accessed over HTTP, FTP, and many other protocols. Typically, data is exchanged in XML or JSON format. Now, in the real world you'll see many examples of web service. For example, in the Adelaide might exported ticket availability status to a travel portal through web service. It doesn't need to give the travel portal direct taxes to its database. A popular way of accessing web service. Rest starts to a representative state transport using raced, you can access the web service and access data in XML or JSON format. Json format is more widely used. There's some contents key-value pair. Any application which wants to extract data from a web service can get a JSON response and directly read that response or convert that with class and object and then read the response. In this course, we'll be interacting between different microservices through wrist. 3. Understanding microservices: Let's understand microservices. If we're to build an application, for example, a course catalog application, we can take two approaches. We can build a huge monolithic application with different modules and a huge database. Or we can build separate service or separate app for each of those modules. One for course catalog 1-4, course ab, and another for user App. And then we can make these applications or services interact through wrist. That is though microservices based approach. The key disadvantage of a monolithic application is if there is a problem in one area, it could take down the entire application. And also, you cannot upgrade individual models without bringing down the entire application. Any day microservices based application, you can develop each of these modules independently without impacting the other. All you need to worry about is what data is getting extends between these services. And you have to keep that in mind while building the services. That is the key idea behind microservices, you build individual models and expose them as services. Typically, we expose microservices through rest API so that they can be access over HTTP protocol by remote clients. While building a microservices bus application, you take a domain driven approach. Juristic, the scope of a micro service to a particular domain. For example, you could have separate service for our service and payment models so that the scope is restricted to one business or functionality. Microservices are loosely coupled. You can build, test, and deploy them independently. With microservices, you can recover from failure quickly. One Microsoft is going down, will not take the entire application down. There are ways to handle it and you'll see some of the examples in our course. So it microservices, you can do faster changes, you can handle failure. You can make your application more available and you can scale your application easily. 4. Microservices learning path: Let's understand how we'll go about building a Java springboard microservices project from scratch. Will start our journey with the Java basics. We'll install IntelliJ and learn some of the language basics. Then we'll dive into springboard and Spring framework. Once you are comfortable with springboard and Spring framework, then you'll jump into building microservices using spring cloud. And then finally, we'll apply all our learning to build a Course Catalog app. And we'll also learn some of the advanced concepts of micro services such as dynamic routing, EPA gateway, and client-side Load Balancing. One question you might have is whether you can start with Spring Boot without any Spring framework knowledge. The answer to that is yes. Spring framework has evolved quite a bit about the last ten years, Spring Boot has simplified Zhao programming. You do not need to understand how Spring used to work in the older days. To get started with Spring boot. With spring cloud, you can easily implement a microservices based application. Spring cloud is open source like the Spring framework. Spring cloud is optimized for Spring Boot, but you can use it in other frameworks. Also. Once you have built a Spring Boot spring cloud microservices, you can easily run it locally or ticket to a cloud environment and execute their. Many of the libraries that you'll see in spring cloud were originally developed by the P bit Netflix. When they tried to build a huge monolithic application for their website, they faced many challenges and then they came up with many design patterns. Spring cloud at upgrade goes design patterns and make them open source. Let's dive in, setup a development environment and then get going with Zhao programming. 5. Installing JDK: To build applications using Java programming language, we require the JDK or Java Development Kit. Let's see how to install JDK. Search for JDK Download. And you will find a link for the Oracle website. This is your 3021, though there are higher versions of Java. Jdk is the widely-used worsen in most real-world production applications will be using Java eight and dedicate. And if we choose to use GATK 11 or any higher version, the code that you're going to see in this course is also going to work in those worsens. Take if Java is already installed on your machine, go to a command prompt. Type Java space does Watson. We can see that Java is not installed on this machine. Will download the report with worsened Pardo Windows machine, you can choose the right one for your operating system. Will ask you to sign in. If you do not have an Oracle ID, you can create one. After dark. You can download and simply click and install. You can keep the default path and click Next. After installing opening new command prompt and type java space does Watson. And you should see the Java version that you've just installed. Before that unit to ensure Java jar it to your system environment variables. Search and click on Edit system environment variables. Click on Environment Variables. Click on part, and then edit. Click new. And RDC Program Files Java, and buy whatever dedicates a new user up to the bin directory, to the path. 6. Installing IntelliJ: We lose in delegative for Java programming is a very popular IDE or integrated development environment in the real world. It's a product from JetBrains.com. Go to the jet, going to upset and click Download. And we'll download the community edition which is free. It's a 600 and B5, which will take a few minutes to download. Once downloaded, click on the installer. It will prompt you to uninstall any older Watson. Then click Next. You don't get this message unless you have any older version installed. You're done, installed the older version. Now you can keep the default data directory and install. This will get finished in couple of minutes. Once the installation is complete, you can launch it from here or you can find up on your machine and launch it from there. You do not need to import the settings. Click OK. Now you can click on New Project. Harder. You can open an existing project. So depending on the version you are using, the interface might look slightly different. 7. Java hello world: Let's open intelligence and click on New Project. And we'll select the project papers, Java. And intelligently pick up the FAR the JDK worsen from this machine. You can choose to many other GDK that might be available on your system. You can also download a particular JDK worsen from intelligence. Let's select Java 1.8 and then proceed. Click Next. Next. We'll give our project name, future Rx, Java one. And finish. You can also create a new project by clicking on File New Project. And follow the similar steps. Let's expand this. And now we see SRC folder under dark, cleared new Java classes and start coding. Let's create a new class. We'll call it future decks, helloworld. In Java that convinced them is you write a CamelCase where the first letter of every word should be placed. Now you've created a public class. Public means it will be accessible from outside. We'll learn more about public, private or not that access modifiers later. Let's simply tape men and hit tab. Create the public static void method, which is the starting point for any Java application. And will write a print statement here. In Java, you rate print statement by saying System.out.print dilemma, darkroom, print to a new layer. And we'll have a string. And then we need a semicolon to end the sentence. Let's write it. It is started building the project. And we sought out put into a console. Now if we write another sentence, let's do that. We'll say system out, print ellen, Hello. And let's execute this. You can execute by clicking on the arrow at domain method or at the class level, or you can execute from here also. Now it is printed Buddha lines. And there is a new line after every print statement because we said print l n, l n stands for GNU Lane. Let's see how to debug programs in intelligence. In intelligent, you can easily put a break point by clicking on a particular line on this panel. Let's say we aren't to execute up to hello one, then put a breakpoint and then debug. So click here. You can debug by clicking on this icon. Or you can be worked from here also, you can say done debug. And it asks you which class to execute. For us. There is just one plus Currently. It printed up to hello and you can click on the console tab. And then it stopped here. Now you can step over. You can go to the next layer. And then the next line will get printed. And under the debugger you can see all the variables. So right now we don't have anything, but later, when the program grows, we'll see how to debug easily using IntelliJ. And you can click here and remove the breakpoint. To increase the Fontan intelligence. You can go to files. Sitting, can expand editor, click on font. You can specify had font increase line spacing. So let's increase the foreign to 22. And you can go to project structure and see different city with GDK worsen and language level or the modules in liabilities. Okay, let's cancel this. Now let's understand this HelloWorld program and how Java works. So when we created this Java class, intelligent would have created it dark Java file, that is future ex HelloWorld.java. You can go to the Project Explorer and see that fail. So this is the project directory under SRC. You can see a file with dot Java extension. Now when we run this program, it would have compiled and created a dark glass which is stored under dog out for lunch. You can go to out under that you'll see production directly, then a project directory and dot, dot, dot plus P. Two. This is the class file that gets executed. When we run it generates the class and grants it. Internally. It's a two-step process. It fast compiles the dark JAR file to create a dark class file and then run start dot class file. And for any Java program, public static void main method is the starting 0.1. Thing to note here is the class name matches with the filename. This main method is where the axon begins. Void means it doesn't return anything. And public means it's accessible to the outside. We'll learn more about access modifiers later. Static means it's a member of the class. In Java, you can create multiple objects from a class. Methods and variables that object level, particularly to keep some variables are metadata class level. You can use the static keyword, will learn more about starting later in the course. The main method can also read command-line arguments. And Java has many liabilities. We use the system class from the code liberty to print the sentence. And in, in delegation is you type something, it will prompt you what are the methods? What are the variables available? You can see there are so many methods available under the system liability. In Java, urate comment using two farads classes. You can see that this line has been grayed out. The compiler ruled ignored it when we learned to do Run As before. And you can also write a comment in line. And to Arctic comment block. You can have Slashdot and hit enter. And then it will create a comment block. Then you can have multiple lines, has commented here. So all these lines will get ignored by the compiler. In Java, all sentences must end with a semicolon. Andres, you'll get a lot while running the program. And also core blogs are written within curly braces. The main method starts with a curly brace and then enter the colliculus. Later on we'll see different loops and other core blocks which also start with a curly brace. And then we'd colliculus. The class alter start with equilibration, ends with the colliculus. You can also run this program from the command line. Let's open the explorer. And we can go to doubt folder. And we have the compiled class here. Let's open a command prompt. And we can run it by saying Java. And the class name without the extension. And Java should be added to the classified as shown earlier. Andres, you lard, we will take Jaccard Java from all the directories. Now to compile Java from the command line, you can go to the main source code folder and open the command prompt to compile the Java future ex HelloWorld java. And it will compile and create a class failure. And then you can run it by saying Java and className without decks tension. It got executed. So this is how you can get started with Java programming language. 8. Java data types and variables: Let's understand Java variables. Java languages statically typed. All variables must be declared report that can be used. In some languages like Python. A variable can be used without declaring. But in Java I don't work. These are some primitive data types we have in Java. Typically you lose biotin sharp perceiving memory for small numbers. You will see in a longer, more widely used in real-world applications. Longer the higher the indenting deters. Florida and w's four decimal values. And double is more precise. And you are Boolean, true and false. You have GAD, which can store single Unicode character. Let's see some examples of primitive data types. Let's declare a short type. And we'll have five. Let's print it out. In Java, we can concatenate a string which is rad sharp with another value. It can be of different derivative by using the plus symbol. So it printed varchar. Let's declaring tape. Can grayed out and hit Enter. It will print the entire system out, print a landscape map. Let's now print variant. And reading card printed will declare a double type. And we'll print the WTO. Similarly, we can have Boolean type. And let's print out also. And all these are variables where declaring of different data types. If we tried to assign without declaring them. You can't have VD double to 30.5. It says cannot resolve symbol where W2 and you will get a compile time error also. You cannot have variables without declaration. Also, the convention is to start the variables with the small letter. And then first letter of every word can be a capital letter. Let's declare a caretaker and catch store single characters only. And if we try to score. Then grid given error. You can just hovered over this and then you can see too many characters in character literal. To store multiple characters. We have something called string in Java. So java.lang, string presents character strings. Let's declare a string variable. Then we can print it out like the other variables. String classes, many inbuilt methods. Let's try out one of those. You can simply put a dot here. And intelligent it would show you all the available methods. And let's do lowercase. And we'll say var string converted to lowercase. Lets run this. We can see that the verge thing is getting printed and also the stringing Lord cases getting predict. Similarly, you can prioritize method substring. Then we have our editor types in Java. It also fixed number of values of single-letter type. And you can grab an element specifying the index number. And the index number starts with 0. Let's see an example. We'll declare an entire array. Let's call it in direct variable. We need to give it as Cij, which the new int of size three. And let's have a semicolon. Let's store some values in data. The index 0 will store them. And then similarly Hit index 12 will store different values. Now let's bring in data value. We can see that it is getting printed. You can also declare that is by directly specifying the values within curly braces. And the value should be separated by comma. Now let's print the value at index two for this area. This would get printed. Here. We can see that these getting printed. So if you know the values, you can declared like this. Otherwise you can declared with the size and then at runtime you can populate the values. You can search for Java documentation and go to the oracle site and learn about different data types and various operations you can do. Let's search for Java is Oracle. We can find more information about diaries and different operations that we can do are not is like sorting, searching, etc. 9. Java operators: You can do all kind of arithmetic operations in Java. Lets look at some examples. We will open the same FusionX Java one project, and within the helloworld class will try out different arithmetic operations. We can do addition, subtraction, multiplication, and division. Let's run this. And we got 74 dietitian as expected and then minus 101200. And for tardy wave for D, we got the G20 because both 3040 Arab dessert types to get a decimal value, we change one of them to her double lot, Florida. Let's make it 30 and now print it. And we will also print party weighed three, which will give us an integer number. Let's run it yet. So 430 by four D, we got 0.75 because one of them is doubled. So the output is of double type. But for 30 by 40, we gotta to do earlier. And for 30 weight three, we got we have modulus operation in Java. If we do 30 modulus eight, we should get six. That is the remainder. When you divide 30 weighed. Record six. Java has different equality operators, like equal, not equal, greater than, greater than equal to, less than, less than equal. We'll see some examples of those. And Java has conditional operators lake, and you can print output based on certain condition. Let's see some examples now. Let's have as clean result will compare d with d. And if it is true, we'll print alpha. Otherwise we will put into beta. And let's ended with a semicolon. Let's print now these n2 equal to 30, it should print beta. So this is how we convey the conditional operator in Java. You can also achieve the same thing with a block, which you'll see later. Now if we say four t naught equal to d, then we should get alpha and regard alpha. Similarly, we can track, record them and regard alpha. Let's check out. And then our operations will save forties and fifties a 100. Then print alpha the ways print Beta. Since we please not greater than 100, it'll print beta. And if we change the R2R, it should print alpha. It printed alpha. Similarly, you can try out our debt equality operations. 10. Java control flow statements: Let's understand control flow statements or loops in Java will declare two variables. Will have a variable a with value ten. And then let say b dot d. In Java, you can write a block like this. If then a condition. If that is true, then do something. We level system or statement. We didn't. If block Henry level sentence outside the block, and the block is written within curly braces. Lets run this. Since a is not equal to B, naught entered this if block. So after result is alpha printed outside the block. And if we change this condition to Nordic call two, it'll enter the harder we can just write the else block. And late. We didn't else block. Now this we didn't else blocks would get printed. See we did else block is getting printed. You can also have elseif in Java. Else-if another condition, and let's say a is less than b, then we'll say we didn't LC block. Since this condition will get satisfied, lard come here. A is less than B in this case. And you can declare multiple else-if blocks. So we didn't LC blog got printed. Let's now see for loop for i equals three. And then we'll say is less than ten. That is the condition. And then i plus plus. So this is our for loop in Java, you pre declared the variable. So starting from three all the way up to ten, it will do some operations. And the Ivan look gets incremented every time. I plus, plus increments the value of i. We, let's print the value of phi here. We can see the value of I0 starting from three all the way up to nine. As soon as that condition is not met, it comes out. You can also look to an array in Java using a for loop. Let's look through this entire two, which is 304050. So the way to do that is for int j in indirect to. Let's move dot here so that we can see the values. We'll print j. So we're looping through this array and printing the value. So we can see the value of j within the for loop. So this is how we can loop through an array using a for loop. Let's also see why looping Java will declare an integer variable K. And K is less than five, print overlook, and European increment k. Otherwise you could get into an infinite loop using K plus plus, we can increment the value. It is similar to i plus plus that we are under did. Lets run this. This should get printed five times. Starting from 0 to five. We can see that really upcase getting predict 5p times. 11. Importing a Java project into IntelliJ: Let's see how we can import a project to Indonesia. Search for intelligent launch it. Then click open, will open the future ex Java project. You kinda project root directory and click okay. It takes a few seconds to scan all files and index them. You can press hard one to go to the project view or once the indexing is or where it Lord medically picker to the project view. Now let's expand the project folder. And we can see the men Java class. We'll delete this dark class, which we had gender card from the command prompt. And you can click on this Run icon and run the project. And the project got executed successfully. And we can see the output here. So this is how we can import a project to intelligence. 12. Java class and object: Java is an object-oriented programming language. Classes and objects at the core of object oriented concepts. Class is a blueprint prototype. And object is an instance of class. Class defines what statin behavior and objects should have. For example, let Doc and a name and color it states and barking and working Tellus behaviors. For a customer. The state can be name, age for number, and its behavior can be walking, got buying. Let's look at a simple example to understand the concepts of classes and objects. Let's create a new Java class. So under the same eugenic genuine project will create a new Java class. Let's call it future ex, oops, demo, who stands but object-oriented programming. Now within this main method, I will just put a print statement. So let's run it. And by default, the new class will not appear here. You can run it by clicking on this icon, or you can go to Edit configuration and change the class name here. Now you should be able to run eugenics, oops, demo from here. So this class got executed. Let's add a new class called Dog. And within that we have three variables. And usually the variables are declared as private and the nuclear public methods to access them. Let's say name, colon, and a double type height. Now this class has three variables or three properties. So we can generate method to access these properties. Now to generate the access methods for these variables, right-click and click Generate, and then select getter and setter to select the three variables. And click OK. Now intelligence generated getter and setter methods for each of these variables. And these are public methods by default. So anyone wants to access the properties of dog can access through this member variables and the variables are kept private. Now let's see how to instantiate this dot glass and create different objects. Let's go back to the main future excerpt demo class. Let's instantiate dog. The instance name will be dog Jack equals new dog should. This is how we instantiate a class in Java. Dog is the class and dog Jack is though object, which is of type Dog. Now we can invoke the set methods and said different properties. For example, we can say, say it height is 1.2 and said name Jack, and said colored black. This though, we can create an object from a class and said different properties. Now you can use the get method to retrieve the print properties. For example, dog Jack, colorist, dog Jack dot get color. Let's run this. So we can see that colored black is getting printed. Let's create another object. We'll copy this. And instead of dog Jack will say D2. We can create multiple objects from a class. And now we'll set different properties. Will have a different height, different color, and different name. And let's print the name of D2. So we can do that by invoking dot getName method. Let's change this to D2. D2 name is getting printed. 13. Java inheritence: Inheritance is another concept of object oriented programming. In inheritance, one class inherits the behavior of another class. For example, doc and innate the behavior of animal class. Similarly, cat can integrate that. We have enough animal class. Let's see how it works. So we've already created a Docklands. Let's delete these member variables and methods. Now we'll create an animal class and will have a property name, private String name. And let's generate getter and setter for name. Now, we can say dog extents any money. This is how we cleared Americans in Java. Now let's go back to the main class. We'll delete this code. And this time we do not have any member variables in dog class. However, dog extends anyone and anyone is name and then getter and setter to interact with Don name property. Let's now in Spencer, dog. Now we can set the name property of the dog. Dog, dog doesn't have a name variable and x's methods, it inherits any one, which is the name variable and get and set access methods. And now we can retrieve the same also. Has a dog one getName. Will run it. Now. You'll forget to R plus here. Let's run it again. And we are able to get the name. Similarly, let's create a cat. And we'll sit got extents. Now let's instantiate that class and create a cat one object. We'll run it again. And Catalan name is getting printed. Now let's add a member variables. Private, double height, knowledge, gendered getters and setters. Back in the main class. We can say the hype. Now, how would this height is not available for the cat? Only state name is available because we added a member variable for the dog class. And cat has the name property because it is available at the parent element level. These are inheritance works in Java. You can have a base class with some common properties and then have other classes extend from it. And the other classes can have additional properties. 14. Java interface: Let's understand another concept called interface. Interface contents, empty method, and any class that is based upon that interface must implement those methods. For example, we can have a animal interface and then define sudden behavior. And then dog and cat must implement those behaviors. So let's see it in action, will create a new project. We'll select the type of Java JDK is getting selected. Let's call it future ex project two will change the directory and you give the complete path to the project location, including the project name. Then it will project directory with whatever name we specify it. Let's go to the SRC folder and create a new Java class. We'll call it future ex hoops demo to let's add a main method. Then artist system out. And say future ex project two will run it. So it's running fine. Let's now Arden interface will select Java class. We'll create an interface with Mmm animal and select the type is interface. Interface coordinates, black methods. Let's hard and new meter wide mix sound. So this method will not return anything. But any class which implements this interface must implement the mics on metadata. So let's now add a new class called Dog. And we'll say implements animal. But in every times we said extent, put interface will have to say implements. We got an error because it says you have not implemented the mixin method. So let's do that intelligent promptly with the method signature. So let's select that will remove the override annotation for now. We'll come back to it later. Now let's put a system out within this. And we'll say, well, let's go to the main class. Now. Inside the main class, let's instantiate dog. And then we'll say dog one. Makes sound. Let's run it. We forgot to add parenthesis. We'll run it again. Now is getting printed. Let's add another class. And we'll say implements animal. Here also will have to. Metadata will give a lower rate. For now. Let's have a system out Mill. And let's know instantiate that got glass. And we'll invoke dot mix on laptop gat object. Let's run it now. Mao is getting printed. 15. Java package: Using package, you can organize these set of classes or interfaces. Package is nothing but a folder on your computer. Let's see how it works. Till now we have been creating all our classes and interfaces, a 100, the SRC folder, which is the default package, but we can create subdirectories or package under this. In intelligence. A right-click on SRC, click New, then click package. Let's give it a name. We'll create a package with men come. And it created a package calm under SRC. And also create package with.com dot future X dot java. There'll be subdirectory future Xander calm, and under future ECS, there'll be a directory called Java. So it created com dot fugal x-dot Java. And let's add a class a 100. This will call it cow. And you can see that the package name com dot future x-dot Java that is appearing here. We can also move these classes and interfaces to the new package. You can select and simply drag. And intelligent would automatically refactor and hardware package name. Now everything is under configured exit Java, Italy's is automatically added the package name. You can create multiple packages. Let's add another one. We'll call it model. And we'll create a class under it. So this class is under the model package and the other classes around other future ex Java package. Let's see how it is stored on the machine. We'll open the project folder and under restarts you will find calm, then future extend Java. So it created three sub directories. And then we can see all the classes here. And for more than one class which is available directly under the model folder. Let's run the main class now. It runs fine. And if you go to the outer directory, you'll see a similar package structure for the dark class files. 16. Java method overloading: Let's understand method overloading, which is also known as static polymorphism, are compile-time polymorphism. In method overloading, we can have methods with the same name and different signature. Let's see some examples. We've opened up eugenics project to project. Let's go to the doc glass. We ever make sound method will add another mix on muttered but with a different signature. And as soon as recopy it gives an error. But if we change the signature, for example, let's say we pass a integer variable, then that eta root go away. So this mattered is taking an integer parameter with some value to it. And then print that. So if we invoke, make sound without any parameter distributed chord, and if we pass an integer value, then this makes our material would get called Should. This is method overloading in Java and you can have as many methods with different signature. Let's have another one. And then we'll just append that. And we'll convert it to let say uppercase. And instead of returning, wired will return. Some value. Will be dumb hello123. Now let's go to the main class. And we'll call dog one makes sound. And then we'll also call doggone make sound written integer value. And we'll call Dao Guan mix sound with a string value. Today, whether it is nice and whatever it will store it in a variable. And we'll print abc. Let's run it now. Here we can see that the three meters have getting involved. First one without any parameters, the second one with a digit and delta1 with string. This is method overloading or starting polymorphism in Java, where you can have methods with the same name but different signatures. 17. Java constructor: A constructor is a method with the same name is that glass, but with no return type. Whenever we instantiate a class, the constructor gets invoked. Let's see how that works. So far in all class definitions, the default constructor is hidden. Default constructor is a method with the same name as the class. So this is the default constructor that is hidden. Let's artist system or treatment here. Whenever we are initializing a class, dog equals new dog, the default constructor is getting invoke. Let's run it now. We can see that I am a dog is getting printed. The default constructor was always there, just that we're not using it. Typically used constructors to initialize class-level variables. For example, we can have a name variable here. And we can initialize died within the constructor. And we can use it. In other methods within the class. Will say My name is whatever is the name. We'll run it again. We can see that the name variable is getting any cell-based and date is getting printed here. You can also do constructor overloading in Java. You can have constructor with different signature, but the name has to match with the class name. Now we are passing name. And whatever name we pass based on that, the name will get decided. And wailing walking dog. Let's say Mike will run it. So disdain. And the class gets instantiated. This constructor will get invoked. The default will not graded work. So you should see my name is make it printed nal. Let's check it out. That's because we did not populate name variable. Now let's give the parameter a different name and this is the class level variable. Later, we'll understand how to have the same name and distinguishes class level variable. We did this skewered. We'll run it again. So now Mike is getting pinned down. So this is how you can overload constructors. And depending on your use case, you can use a particular constructor. 18. Java this keyword: Let's understand this keyword in Java. Using this, you can access the class-level variables. Earlier we garden needed when the metadata variable name and the class level variable name had the same name. Let's see how to address that with this keyword. We can have same name here, but we can access the class level variable with this.name. Now this will work without any issues. And the poor do not have conflicting variable names, then this keyword is not required. But it's always a good practice to use this.name in your methodic for accessing any class-level variables such as name here. Now this will find, let's see another example. We live at new constructor, which will take height as a parameter. And we loved survey class level variable height. Now will say based Dart height equal height. And let's adjust it little bit height plus1. And we'll print it out. We'll pin them at our document here. And my adjusted height is, we'll print the class level variable here. Now let's run this with a double value so that the other constructor would get involved. So my height is 3.4, whatever we passed. And they're just heard height is though class-level variables, this.title. And we've added one to whatever value we passed and populated died in the class load variable. So this is how you can use the, this keyword in Java to use class-level variables. 19. Java access modifiers: Let's understand Java access modifier. Java has four different types of modifiers, public, predicted, nobody fair and private. And these modifiers are applied to a member variable. Automated targeting modifiers beside at what level the variables or the methods will be accessible later. Class package, class are accessible to the entire world. If a variable or method is public, it is accessible everywhere. Class packets subclass, end-to-end outside application. Protected members are not accessible outside the particular application. It's accessible at class Pakistan subclass levels. If there is no body fat, it's accessible at class and pack is liberals. And if something is private, then it is accessible only to that particular class. Let us see some examples. Let's start a new class. We'll call it. Of course. We'll declare for variables with four different access modifiers that we just discussed. Let's say public course name. Then we'll have protected string name. Private int, number of reviews. We live with no mortified number of students. Let's now create another class called machine learning. And we'll have it extend from the course. Now let's create another class which will be our starting point, Abduh demo. We'll call it access demo. Now let's go to the course class and create a constructor. We leave me CLAs default variables within the constructor. And we can access all the four variables within the same class as where the access modifier charge. Within the class, all four tapes are accessible whether in the constructor or in any metadata. Let's initialize all four. Now we learn a method called display details. And let's have the return type is void and will simply print all four. Now let's go to access demo and we'll write the main method you can pay PS VM also hit Tab. Recreate the main method. We didn't that let's instantiate the course class. Now we'll call coarse one dot display details. Let's run it. So it got executed successfully and we're able to access all the variables with the courts class. Now let's go to this Machine Learning class and create a new method. And we'll try to print all the values. We can see that course name is accessible, autonomies accessible, number of twenties, accessible, number of reviews is not accessible. It's getting highlighted in red because that is private. And it is all within the same package. This we cannot access. The remaining three are accessible. Let's instantiate this class. We'll call it ML deployment. And let's display the pills. And we lard machine-learning here, just to know that the Machine Learning class, let's run it. So we are able to access the public protected and the no modifier variables. Now we'll go to the model package and cleared a class called Hadoop. So this is in a different package, tandem course class. And we can extend course. Since it is in a different package, that package needs to be imported. And IntelliJ geodata radically board that. It's saying there is no default constructor available in the course class. Though there is a constructor did not have any modifier. So that's not accessible outside the package. If we change it to public, that data will go away. Now in the Hadoop class, you can ardor constructor and call super, which is a call to the constructor upto parent class to verify that is accessible. And let's see if we are able to access all the four variables from this class which is similar, different package. So now we can see that number of students in number of reviews, both are not accessible. Number of Corinthians nor modified and now whatever the Bouazizi private modifier. So these two variables are not available outside the package. Some examples of access modifiers. And if we're working in an ID and Robert Lake in Delhi j, all the errors should be highlighted and you'll be suggested with the fixed. You really don't need to worry about whether you are setting something correctly or not. But it's good to have an understanding of how access modifiers work in Java. 20. POJO, Java Bean and Serialization: will you come back? Till now, we have seen Java classes, objects and interfaces. Let's now look at the one of the Tom or standard that that is there. In the Java world, it is called Pozo Plain old Java object. So what does it really mean? The concept oppose a was introduced by Java some time back toe being some sort off standard or or globally acceptable former with the Java community. So there are some standards for the class must be declared public. Properties of pills must be private. So we have created Java classes and we are some feels and let the private that is because of the poster standard and must have public getter instead of matters so that anybody wants to interact with This object came in tracked through gator inside of matters, so this should be public in produce 11 different constructor. It can also a personal constructed with documents poses make the program more reliable and increase its visibility. It is kind of the global standard now for Java development. If we're building Java classes and objects, you keep in mind approaches standards while designing them. Next coming to Java bean, a bill is a pozo, but additional it must be serial Izabal. So let's understand what is. The relation is serialized. Object is converted to bite, stream and stored in memory or a tent or databases or it in the file system, and the byte stream can be this realized to reconstruct topped it. Serialism helps in sharing objects, so that could be multiple Java instances. Running in an inter praise, you can take a knob checked from one instance, serialize it and then share that serialize object with another instance, which can be serialize it and use it and serialize update can be cast for faster data upriver. It is faster than recreating. The object you see realize it cash it and D C realize it. And use that to suffer another plan, which is a question for the same object. Rather than trying to build object again, we can also itchy persistence by storing intimated state of an object with simulation. So let's say there is an object with certain pills and the pills can get changed. For example, number of users enrolled for a course can change, and number of reviews for a course might change. So for the northern intimidate State off any object you condition allies the intermediate state and know that it is heavily used in database And it is to store intimidate states which we'll discuss later when we start talking about Javadi This inflection now how we make an object see relatable. We do that by implementing Jabhat IOC realizable in defaced and then the object becomes cereal Izabal So that is all about puzzle job in and simulation. Thank you. 21. Java dynamic polymorphism: Let's understand dynamic polymorphism in this lab, you have earlier seen method overloading, which is a static polymorphism, are compile-time polymorphism. Dynamic polymorphism is runtime Baldwin. Let's understand through some examples. We have an animal interface and gotten dog classes. At implementing that interface. We are instantiating the dog and cat class and using them. Now let's comment out this code. We can also instantiate the dog with diabetes anymore. So instead of dog one, let's make it anyway, L1. So this MML e1 is of type animal. But then when we instantiate, we can say it is it whether it's a dog or a cat? Let's run this. Now is getting invoked because while instantiating we are seeing is a dog and if we change it to cat. Now mu is good invoke. So this is dynamic polymorphism, though animal One is of any type. But depending on what glass we instantiate it to, it takes that form. You can also have dynamic polymorphism with inheritance. If we change this to a class. And if we give an implementation here. And instead of implements will say extends. And similarly in the getClass extents. So now we have an animal class and then dog and cat start extending the animal class. And this would work is we put dynamic polymer which can be implemented with both the Americans and the interface. And any Malkin also take the form of a minimum. If we run this makes on of the Animal class will get invoked. 22. Injecting an object: In the previous slide, we saw how the same object can take different forms depending on which class we map it to. However, if we look at this curve, this is a tight coupling. So here we have to specify every time whether it's a cat or dog. And then depending on that, either cat or dog object will get instantiated. Now to understand this better, let's change this class name2, animal speak. And we want this animal speak class to speak like a cat or a dog, depending on what we decided that untamed. Now let's remove this main method. We learned a private variable called animal, and then let's add getter and setter for that. Will remove this also. So now this animal speakers in animal class variable and then it has getter and setter methods. And we'll artist speak method. This animal speakers animal type member variable. And then it can invoke them exon. Now this is no reference to cat or dog. Now we have to make this animal speak either speak like a cat or a dog that aren't aimed to ensure there is no reference to cat or dog in the animal speak implementation. Now to achieve the same, we'll inject the gatt dot dot class at the runtime to this animal speak class. And depending on what we are injecting, the animal speak could create an Animal object of that particular type and invoke dot corresponding speak method. We learned another class, animal behavior. Now that class would be our entry point. And let's move this outside this package. And we'll rename this Packages com dot future external animals. Now we didn't go anywhere beyond. Let say we have main method will import the animal speak class. Now we'll set any malice, cat or dog. Now let's have an enumerated type. We'll call it new cat. Will instantiate the animal with Gatto duck tape and then past data Animal object to the animal speak class. And we'll call does anyone speak, makes unmetered now. And we'll run it. Now is getting printed. And if we change it to dog, let's import dog. Now animal speak is calling the speak method of their dog. Plus, this is how you can inject an objective, the runtime. And depending on what object you are injecting, a particular module will behave in a certain way. This is a very powerful concept. Dependency injection is a core concept of Spring framework. And if you have understood this module, it'll be easy for you to pick up what we're going to discuss next in the Spring framework. And Spring framework has simply fire dependency injection using something called annotation. So let's understand annotation concepts next. 23. Annotation annotation annotation: Welcome back or let's understand, Java under obeisance you for new to programming. You might find it a little hard to understand. Initially, however, annotations simply five job programming quite a bit. I don't Patients are used to provide additional information. Toe classes, metres, variables, constructor. You tell the job program classmethod variable to behave in a certain way. The best way to understand annotation is by looking at an example. Let's jump in and create a new project in intelligence created huge our project. Give it the name our animation demo finish. I want to go to the project view. Let's globalize ourself for that and create a new Java class with Limited is animation example to gender Public static Wardman matter. Simply type PSV, um, and hit tab. You'll get the court. Let's hard another class called animal class. We'll have a simple speak mattered within animal class. Let's start a system or statement. Let's add a dog class, which will inherit from the animal class. Dog extends any month and ever different system. Elon's statement. Now, let's instance it the dog class and involved the speedometer. So this one served the involved a speak matter of the dog class because we were worried in that In the dock class, Footprints dog is expected. But what if there is a typo in the middle name? Let's say we father toe right, speak. And then there's a table. It's only during the run time that will realize that it's invoking the animal method by mistake to enforce the dark last overrate, the speak method. We can use an annotation. We can just simply rate the rate overrate. Then this method, sure over raid one of the methods in animal class. That's the way appealing the compiler there. This matter should operator in the middle, and it doesn't find the matter with the is capital piece or given it up. You change that run fine. So by using the override an impatient we're able to tell the compiler for the speak maturity, the dog class to behave in a certain way. Now it prints Dog is expected. You just saw an example of how to tell the Compiler hotel a method to behave in a certain way, academic class to be even that certainly, and we achieved that through an innovation. You'll find many examples up annotation in spring framework and in spring book whose you're going to discuss next. It could be a little challenging for you to initially understand why we are doing annotations or why we're writing a vision. It's actually it simplifies a lot of things for the developers. You do not have to really worry about what is happening there and annotations how the quarter configurations are getting generated. All you need to understand is a big note or is a person who is new to spring. For Marcus, the class are the metal where you see that rotation is expected to behave in a particular way, and you go and read more about the documentation of that particular irritation. With also explained that there during the course of the lab. So that is the best way to get started with innovations in spring framework. Prior to annotations, we used to do all configuration in spring framework in the XML file, which was kind of quite tedious, and developers did not like it, and annotations simplifies a lot of things. Those were completely new. Plantations need not try to understand house being used to work in the older days because annotation has married simply for you. So if we're just getting started, just get used to the fact that there will be a lot of annotations. An annotation will tell particular classmethod are construct variable to behave in a certain way. Just accept that. And then I think gradually you'll get the more understanding of annotations. And then you can appreciate how it simplifies the overall programming fourth Cartel Oppa's . And it mentioned I lived. The complexity of all the court and configuration is hidden from you. It is there in the framework, in form of Java class or libraries. But then is an individual today. Is it? A leopard wanted to focus on writing business logic just your used annotation, and you can expect the method of class to behave in a certain way. So that's the best way to get started with annotations. So let's land spring from work next, and you'll see plenty of annotations in almost all the examples that we see. And we try to explain the concept windows ambition so that it would be simple and easy for you to understand. Thank you very much 24. Spring Framework and Spring Boot Introduction: Welcome back. Let's now understand Spring framework. Using Spring framework, we can quickly Java enterprise applications. Spring provides a template for common services like transaction management and garbage collection. Or developers focus only on writing the business logic and the framework could take care of all the common concerns are common functionality. Additionally, spring provides infrastructure support like Database Connectivity. Spring framework has evolved quite a bit over the last ten years. At developer needs to know how to make it work by doing the right configuration, setting and following the character billion deployment process. Build and deployment effort for a spring framework application is quite high. So that takes us to springboard. Using springboard, we can quickly be less ping application. Boots stands for Bootstrap. So as the name suggests, we can use Spring Boot and use the pre-configured application to quickly build and launch a new application. Spring boot is an opinionated framework. That means it tells you how to build an application. Washed up the features and functionalities for non-functional requirements are already given to you. And you can take this rebuild application and do your customization and build application. Spring boot is the way to go to build any Java or spring application, whether it's a website arrest surveys are a backend batch process. You can take the pre-built dot preconfigured Spring Boot application and apply your changes and just run it will be taking you through some practical examples to understand Spring Boot better and understand how easy it is to create an application in no time or to know more about the Spring Boot framework and spring, you can visit spring dot W0, which is then often sell website is mentioned here. Spring Boot makes it easy to create standalone production grade application or just for development and POC, you can take the pre-configured spring application and deployed on production. Springboard come sit and embedded Tomcat server. So you do not need to create worthwhile to deploy your web application. You can use the embedded server or to host your application. Let's now take a look at all the PBL preconfigured applications that are available for us since springboard a go to the bottom of this page. Spring initializer link. You can also directly go do star dot spring dot IU. In this page, you have to select the Project tab where there is a mammoth project of democratic. We're using Java language and discourse, and we'll choose the default. Does springboard worsen? That is shown here, 2.2.4. Next unit to choose the dependencies depending on the application you're trying to build. For example, for a web application you would choose Spring Web. Similarly, there are other dependencies. Have a leg bone for a rest service for our backend database interaction with GPA, etc. Select all your dependencies. Click on this generate controlled button that you see at the bottom of the page and generate top preconfigured application. 25. A Hello World REST service using Spring Boot : Let's build our first springboard up in this lab. We'll go to Start dots sprinkled. Do Note that the interfaces changed lately as of January 2021. However, the steps to create a project are pretty much the same. You select dependencies here and specify all project material, the information in this section, and then you pick gender can create a project. The default project tape is Maven, and we'll be using Maven for build and dependency management in this course. Using Maven, we can easily manage all project dependencies and build a project and created deployable jar file, which can be taken to any environment. We'll talk more about May one later in the course. So for now let's select product tables. May 1 languages, Java, and whatever spin would worsen. We see here. Group name is the root package name for your project. I limited com dot future x-dot microservices. Artifact mimics the project. Mmm, let's call it spring HelloWorld description. You can leave it default. And the package name is group name, including the project name. Let's select Java eight here. And after that, we need to add dependencies. Since we are learning microservices In this course, we'll start out springboard journey with a simple rest service, search for riskier. We can see Spring Web dependency at the top. Using spring where we can build websites and also RESTful web services. You can also build wrestler EPA's using risks repository. For now let's select only splitting web and create a project. Select data and agenda the project, Clicking on that gender button here. Spring Boot creates a startup project based on these options. And when you gender it creates a zip file which gets downloaded. Let's unzip this fail. So let's open IntelliJ J and Lord this project. Go to File New Project from existing source and select the project route directly. Click next. It picked up the project name. The project name is by default whatever is the root directory name. You can keep everything as depart can click Next. Next again. And we'll select JDK 1.8. Click Next. Then finish. Let's open it in this window. Now it's prompting us to load it as a Maven project. Let's click on that. It will take a few seconds to read the bomb dot xml and cleared the project structure. Let's now go to Palm dot xml. We selected ME One is the project type and every Maven project has a palm dot xml file using which all the dependencies are managed. Spring Boot startup paste is the default dependency that gets added using which a Spring Boot application can be tested using different libraries such as JUnit, Jupiter, Mockito. And we selected web-based their dependency to build that SDP. And that is getting shown here. So based on this, intelligent or download the required jar files and keep it under external libraries. Initially you see JDK liquid liabilities here. As soon as May one results all the dependencies, all the springboard or later liabilities will be shown here. Now we can see that intelligence downloaded the required jar files for springboard application. Springboard creates a JAR file under SRC Main Java, and whatever package you specified. And that Java class is the starting point of the application. In this case, spring Hello World application is the starting point of the springboard application. And there is a Spring Boot application annotation which tells the compiler that this is a Spring Boot application. Now we can run this project, but we can see that not all dependencies have been dissolved. Spring Boot application is appearing in bread. If we get the same error here, I refuse troubleshooting tips. Right? Click on pop dot xml, select May one and reload project. They want to try to resolve dependencies. If that doesn't tell, delete the main.xml file that you might see under the main folder. Sometimes it creates conflicts. Simply click on it and dot delete. Half cooked that intelligence should find all the required dependencies. We can see that all error's highlighted in red are gone. Now this is a web service that is ready to be executed and deployed. You do not need to make any additional coder configuration changes to make it run. As a developer, you need to concentrate on adding business logic and creating an endpoint for your list web service. For now let's artist simple system or statement will print out Hello World, string and run the application. Now it is started running and we can see springboard in the console and the Watson is getting printed. So this is the default log that Spring Boot dendrites. Now we can see that the spring Boot application I started running and there is an inbuilt DOM card webserver, using which the Spring Boot app has been launched. Also, we can see the HelloWorld output in the console. Now let's try to hit the web service it localhost 8080. We can open a browser and Lord localhost 8080. And now we got an error. This is expected. It says application has no explicit mapping for class data. When we invoke localhost 8080, it's looking for a mapping or some functionality which mapped to the root directory. And we have not specified anything for that. Traditionally is a fallback. Gets trained to look for class several URL, but we have not provided any mapping quartz glass that are also. Let's understand how to provide a mapping to a URL. We learned new Java class. Let's call it hello service. You can specify any name. Now to start with a rest API using this class, we need to R then M relation called wrist controller. And as soon as we do that, intelligence imports the required package. Next we'll add a maternal and map it to a URL. Let's call it index. You can give any name. And we'll return a simple string. We need to add an annotation request mapping with the URL to map it to this method. Let's map index to class you had, which is the root directory. Let's put a semicolon here and fix that typo. And we'll run it. It is started running. It's running now at port 8080. Let's refresh this page. And this time we got the message Hello World 2021. And this is coming from this index method which is mapped to the root directory. The method returns a string which is sent back to the client. Let's start another method. And this time we'll map it to slash abc widen, and we live a different return statement. And let's change the method name also. Can not have two methods with the same name. Will run it. Similarly, you can create ties many method send, map it to different Tile URLs. So this is how you create a risk TPA using Spring Boot. You create a method and then map it to a URL. Also, you need to ensure the annotations are added. Rest controller at the class level and that equipment mapping it dumb. At third level. It is again started running. First. This, this works fine. And now we'll invoke does class ABC URL. And it returns message from the method that is mapped to this class CBC URL. So this is how you can get started with springboard. 26. Dependency Injection Using Spring Framework: Let's revisit the animal speak demo that we did earlier. We are able to inject the dependency animal at the runtime cinnamon speak classes dependent on the Animal object which we are able to injected the runtime. We are able to tell it whether it's a dog or cat than animals. Pig was able to invoke the corresponding speak method. Now let's understand how to do this dependency injection using the Spring framework. We'll go to Start dot Springer Tojo and create a new project. We'll limit as Dependency Injection demo and will not select any dependencies for this lab. Just simply generate the project and extract the zip file. Now will load this project to intelligent, go to File New Project from existing source, select the folder dependency injection demo. And click OK. We'll select the build type is Maven. It's open it in a new window. Once all the jar files for Spring framework and loaded, the project folder will be visible and you go to SRC. And under that men, under that Java and under that you will see the main spring would turn demo application class send here you will see spring up Listen.com. There is an annotation springboard application that tells the compiler that this is the springboard application. We just added a system out statement. Let's run it. So this will run the spring application. So everything looks good. Let's now implement the animal world project using this Spring framework. We'll copy the classes from the older project to save some time, you can simply copy and paste. And when you pace, you paste to counteract the package. And you can see the new package name for each class, slips copy animal, animals, speak, cat and dog. These four classes we need we don't need to copy the animal waiver class because Dependency Injection demo application, this is them into point for the new project. So here let's copy the code that we earlier wrote and just run it. And let's see if everything runs fine. We have not made any changes. And it prints 2v. And then for cat, it should print amino. Next will tell spring to manage these beans for us. The way to do that is through annotations, will go to each of the classes, will add component annotation. So that will tell spring that. It's a bean, needs to be managed by spring. Will add the annotation to both cat and dog and also to the animal speak class. Now let's understand how to inject the beam using this Spring framework, we should be able to inject the Animal object to the animal speak class. So the way to do that is by using another annotation called auto. Auto add annotation till spring. What Beamer classmates to be injected at the runtime. In the older versus an offspring framework. Dependency injection was AC through XML configuration. Now Spring Boot has simplified our dependency injection. All you need to do is write an auto add annotation and then Spring Boot to detect which object needs to be injected at the runtime. Now let's comment out these two lines where we had instantiated the classes. So will be getting the classes directly from the spring application contexts. So spring applicants, some contexts, it holds all the beans. And spring application.rb returns the application context. To get the BGN from application context, simply use the getWidth method and specify the class name. Now let's say, sayin the beans to the variables, and rest of the code would remain the same. So the change that we made was within the main class, we do not have any reference group, dog or cat. Now let's run it and see what happens. It failed because we have two components. Animals pick doesn't know which component to even check whether queens, a cat or dog. Now to address this, we can simply use the another arm patient call it primary. So this will tell the spring claim of that cat Bean needs to be injected because that is the primary annotation. So you can see me all got printed. Lets now move that primary to the dog class and run it again. Oof is getting printed. So this is how we can inject dependency at the runtime by managing it through annotation using the Spring framework, we used auto aware it component and it primary annotations to a cheaper dependency injection using this Spring framework. So as we move along more microservices journey will see lot of examples of annotations or toward annotations, bean annotations. Hopefully this intimal speak example at giving you a good understanding of dependency injection, which is a core concept of the Spring framework. Thank you. 27. Maven for build and dependency management: they come back. Let's understand. Marble. The selected Mavin is the building tools for dependency. Management, while downloading a springboard application, are creating a new project in intelligence. Let's understand it in more today. Difficult image, our application to use any external morning look too hard. The corresponding Jack files manually, and they'll hard them to the class foot with Mabon. All the Jack files will get at it automatically. All you do is specify the required dependencies. All Mavin products come with the partner XML File Holly Could do. Is are other dependencies informed? XML file Dependencies are nothing but expel models or jars that you would be needing in your application. Then Mabon would automatically download those stark files from Mavin depository and our them to the classroom inability or prompt you to download the job files as soon as you had a new dependency. Or you can set the heart of downward option. Two years apart from managing. Dependence is you could use Mammon is a big toe. Later on, in the practical systems will understand how to use Mammon building back his manager to create a jar file for our application. Thank you 28. IntelliJ Quick Tip - Maven Reimport: Welcome back. Let me give a quick dip on intelligent idea. Sometimes when you import products, it fails to run and there is a way to handle it. Let's see that in this lab. We'll go and download the hello World project from you. Jimmy. Simply download it from the resource is six on zipper. Now go back to Intelligent. Try to import this project. Find that folder select Maven Upson and it takes some time for the left hand panel to show . Although source Gordon Resources this wait for that. And when you see a SERC main job for not everything has been interested in intelligence and then you could run needing for the pain. And then there is another way you can important despotic from existing sources. And this is the bomb. Fine. Through it, we manage all the dependencies. But sometimes you will not find these ramekins here for some reason. And even if you find when you click on it, you don't run. In that case, you have to go to the Palmer XML and we're having a really good So this year download all the required dependencies jar files, then your project. There's a little drum fine. And they were also prompted for import or to say they are to import on here at the right inside at the bottom of the off Indonesia window. Just remember that maverick Greenport and then all of your friends will be put it. And sometimes it just gets important automatically. But if you're a huge project Germany dependencies, it takes time or it fails to important. There is a connectivity issue Are because of some other reason. But make sure to do mavin cream pork and you should be good. Thank you. 29. Creating a Spring Boot application with multiple dependencies: Let's now create another spring application with few Additional Dependencies. Who do startups spring data you will give the application name is core. Sap will add though with dependency. And let's also add our spring data GPA, which we'll use to interact with the database. And we'll also add the Register positively dependencies. So now this application will abort the required dependencies for a web application, for a rest API, and also to do database interaction with spin delta Gb. Download the app and ship it. And let's now put it into intelligence. Go to File New Project from existing source and select the New Courses folder. So now this project will get imported. Suspend Mammon is that dependency manager. Click finish. And we'll open the project in this window. Last Castro terminate all application. Pre-installed one, and you'll be taken to the project view. Expander, SR, Main Java. You'll also see a Java class like the last name. And in the PalmPilot XML will see additional dependencies like springboard, GPA, Spring Web, and spin STP. The three dependencies which we selected and all trees you can see have been added to the permanent exhibit. Now let's run it and see what happens. It failed because we have not really specified an EGP repository or database. Although we have our interdependency, let's remove that dependency from the palm read XML. For the time being. We'll first build an app that later when we create a database, we'll add dart dependency back. Now if we run it, it will run. So we have two dependencies. We addressed EPA and the application will run as before. And using this, we can build a web application and we can also build wrist EPA's like the last thing. So in the next lab we'll explore how to return a core subject to backwater HTP instead of just a simple string which we planned out in the previous lab. Thank you. 30. Returning an object to REST API: Welcome back. In this lab we'll understand how to return an object back to the STP. Let's add a controller using this class. So we manage the risk DPA interaction. Let's add the rest controller ambition that we have done earlier. And will also create a good courses method and map it to course's URL. So created a controller now with the required adaptations. And let's run it first and see if everything is fine. We should see all courses. So this you have done earlier also, let's not try to return an object. Will create a new class called course and add some fields to it. Let's have three-phase course ID, course name and author name. Let's generate getter and setter methods. So created for the course ID field. Let's simulate it for the remaining fields. So now I've generated getter and setter for all three fields. We now are at a constructor using which we will instantiate the object. Select all three fields. Now back into course controller. Instead of returning a string, will only stop objects, which will be core subjects in this case. So let's create instances of the course Class. C will create three objects, specifying the course id name and author name. And using the res.json to will return a list. String could convert objects to the JSON format and displayed on the webpage. Let's now run it. It gives some error. Just make sure all the field names are correct and all the required libraries are important. For list, we need to import Java util list package. Make sure all the field names are correct. Now when you refresh the page, you should see all the objects in JSON format. So this is how you can return an object back to the rest API. In the next slide, we will understand how to integrate a database with a spring application and return data from a database table flourished EPA. Thank you. 31. JPA, ORM , Hibernate and Spring Data JPA: Welcome back before we start working with database image of application. Let's understand Java persistence a p a r G p Using Java persistence AP A We do all kind of established operation in a job application. Earlier, we used to write all the queries in a job program and use their jelly BC driver to connect to the harvest. And once the reserve is faced with to convert the debtor to an object manually or extract data from the secret local and then use that in the program, developers used to spend a lot of time in managing connection managing transaction and converting the sequel out to objects to simplify database operations. A concept called Object, relational mapping or wearing was introduced, so the idea was to create Java classes. We should map through the obvious stables, and the one framework would take care off, keeping the database table and the Java objected Memory in sync and developers could work directly on the Java plus without worrying about how the dead eyes getting gushing without that stupid with wearing the Nevis interaction was simplified father developers because all their to do us mark on the Java classes, we should store the data in the memory not only about interacting with the physical energies. GPR Java Persistence epi A is the week use order. He provides a pays to manage relational daytime job applications you need to implement G. P. D. PH. Just a guideline or specification. Hi one. It is in wonderfully what which implements worry or JPs specification. Its main job is to map job, Arctic student in the stables suggest. To summarize JP is the specification, and hibernate is one of the most popular ways to implement GP or Java persistence. Spring provides a model spring did at GP the work with GP and simply by all the date of this infraction Hollywood to do is include the spring that a chippy a dependency and then use the classes available in the chippy repository toe. Do all kind of database operations will be exploring more on it during the practical sessions. Thank you 32. Installing a SQLite Database: in this lab will installed seek related abyss, which is the rubbish, which you can easily download your local environment and use that to integrate with the spring application. Good article $8 Pitch and search for by Mary for your operating system. In my case, it is good windows Such about this particular is your friend. We says bundle of command line tools for managing the sick related abyss. Once you don't love this and keep the fight and then thistles your database for that, you can go to with that particular for that in the command, prompt and simply type Speculate three. And you were taken for the circulate problem. Here you can start reading all your queries. Dark Quit is the command to come out of it. Not to ensure this sequel. Eight databases accessible from all folders, Good windows, environment variable and they read The Path toe are the new part for the circulated of this . Now you can access the secret three committee. Initially there noted a basis. So when you my daughter that basis, you will sit on the stock databases to create it, ever simply type speculate three and some of its named RTB and then you know that this will get created. We can ended up. It's called Future Ex School Start BB. Under this particular folder that you can simply create, they will let's get it able with some fears. And then we can face that I Initially there'll be nothing. Let's in sort of your records on. Then try toe fetch again. We can see that with the consecutive face. So this is how we can have a local database on your machine using secret light and use that to integrate with spring application. 33. Fetching data from database using Spring Data JPA: In the previous lab, we have seen how to pull data from a Java object, convert that to JSON format and displayed on the webpage using a risk to a service. In this lab, our goal is to pull the data from the course table in the sequelae database that you've just installed and display it on the web page will be using the same spring application. Let's understand what are the changes that are required to connect to the database and display the content in the website. We need to ensure the SQLite database project folder where our Java code is, so that the spring application can easily find that database. Go to that folder type CMD, and you'll be taken to the command prompt with that directory. Here, let's create the database again. Tapes cingulate three, which are X dB, and the database will be created. Let's take the database name and Civil List of table's. Currently nothing is there. We'll create the course table again. And we'll insert a few records. And then we can verify if reconcile inserted or not using the silicone. Gather to records which are already inserted. Let's fit these two record send displayed on the webpage. Let's go back to intelligence AID and understand the changes required to integrate this application with the new database. In the previous lab, we created di instances of course object and return that to the rest API. And the contained got converted to JSON objects and God displayed on the webpage. Now we'll try to map course to the database table so that instead of creating the objects manually, we'd be able to return the data. Go to the palm print XML. And we need to add the dependencies for spring get at JPL, which we had removed earlier. Let's add that back. And we also need to add dependencies for cingulate. Go to Melbourne repository, search for Simulate. Click on that link, pick the latest versus 3.30.1. So this will add the required jar files for SQL database interaction from the spring application. We also need the another dependency or to write all the queries, select, update, delete, insert queries. There is a SQL dialect package that is available that you need to use search for that circulate dialect Maven dependency. Let's use this particular dependency. We can take the licensing terms. It's perfectly okay to use this open-source library, manage your database interaction, will take this dependency and dyadic. So now we have one for one for managing SQL queries. Now let's understand how to convert this course Class Database entity. We can do that by simply adding an entity annotation. Make sure it's of type Java X persistence. Now we need to ensure the column names and the class variables match. So we have cos ID, make sure it is course id all small. Otherwise, GPA would look for a course underscore ID column name, course name all small, and make it author all small. Now we need to make sure core site is the primary key circular arc. Idea rotation. And make sure the required classes are inputted. Let's now delete all the old methods. Sender will generate getters and setters again, and will also generate a constructor. We do not need to select any field. Will create a default constructor. And then we'll create the getter and setter methods. Select all three fields and generate getter and setter methods. Now we have an object created which is going to map to the database. Course table. Will just rearrange it a little bit, all the variables at the top and then constructor and all the methods. Let's create a new interface called core repository, using which we will manage all database interaction. Select the type is interface. And this interface would extend the GPA repository, which is a data access object or Tao. Tao has built-in methods for database interaction like select, insert and delete. We need to pass the payable limb that is course, and select a big integer which is started or type of the primary key ID. And makes sure the GPA repository packages included. So this interface will now help us in interacting with the database table. Now back in the controller will inject the new interface using Auto where denotation, create a new variable, of course repository type, and add Auto where denotation. And let's delete this hard-coded values. And we'll simply call the findall method of the course Repository class to get all the values from the table. So this will be mapped to the course class, which in turn is mapped to the database table so that CP repository tau object. This should now give us the two records that we have in the course table. We have kept the request mapping adaptation intact, ingress controller annotation intact so that this will map to the corresponding rest API. Lets run it. Okay, let's correct this terror slippery term course repository find on it will return the list of core subjects. Let's now run it again. This will fail again because though we have created a database and modified code to interact with the database, you've not really told spring how to find find the database. How database future ex course DB is presented the project folder. But spring should be aware that this is the database that we are going to interact with. And for that, we need to go to the Resources folder and find the application dot properties. Within that, we'll specify the database, a connection parameter or details. So to understand what are the properties that we interest specifies search for Spring Boot application properties. Go to their officer page for Sprint good application properties. And here you can find all the common properties. The first property here is database type, which is in our case. Next, we need to set the hybrid net DDL auto property. None otherwise, hibernate will recreate all the tables which we do not want. You already have database and tables created. Pro means all the SQL queries will get printed in the log. This will help us in debugging. Data source URL is dot database name, which is feature, feature X course DB. In our case. It is in the same folder as the project folder. Username and password. We can leave it as blank. We have not really specified username password while creating the accumulated at this. And finally, we need to keep their driver className, which is JDBC in this case. Let's run the app now. And this time it ran successfully. We can see that the app is running it. Port 8080. Refresh the page. You'll see the records getting pulled from the course table in the sequelae database. Let's insert another record to the same table. We created a third record. So there are three costs now. And when we replace the webpage, who should see three records? So this is how we can pull data from a database table, can displayed on the webpage using a spring list TPA. Thank you. 34. Spring Boot Advantages: Welcome back. Let's revisit some of the springboard advantages with spring book were able to quickly build an application and make it up and running. In no time you have seen how we have built a list AP A using arrest controller and then how you connected to the database and face the gate and displayed it in the website in minutes without being lot off configuration before spring. Would it is protected a lot of time to do the configuration, create a white file and deploy and launch and then sit out. So that is the advantage of for spring book. It takes a reputed view on how spring applications would be better block you. Take the pre built structure project and make your changes related to your business logic, and then you can quickly deploy and see the output. You can quickly build a rest API or a website with front pages controller database without really worrying about how to make different components. What all in the concentrate is, what is the business logic that he should be writing specific to the application. Also, with springboard were ever to be the standard on application with an embedded tomcat server . We're not creating a work silently, bring it on it with someone. Springboard produces a self contained job. Find that contents that very conquered suffer, and you can take the application and learning in the Java environment without worrying about application server configuration. 35. Postman REST Client: Welcome back in this level. Understand how to use the Post Wendell to send a request to the application we have been sending simple Get our faith request within the browser party. Feel, too. Let's ascend that are put application to inserts an update believe then will abuse some kind of rescued and postman is a tool that is available in the chrome app store. Just go to the room, which torrent. I installed the APP, and then you can start using it to interact with your application. Once you install it, you'll find it in the grow maps section. Click on it. You looked so sign up with Google. Give your user name. Now let's see how the centrepiece to the application using the post print So we have the course are running well. Simply take the U. N. And use that Fitch Data from the application within a get request to the courses seawater. And you can see that the responses getting faced and it is nicely formatted for you. Do you the content similar you can't send posed delete on update request, which will explore in the practical assistance 36. CRUD operations using Spring Data JPA: We'll come back till now we have seen how to fate shot data from the database using the crowd repository findall method. Let us now understand how to do other kinds of database operations such as insert, delete, and update. First we'll make some changes to the course NPP. We'll add an annotation JSON ignore properties, show that some of the additional implementations of hibernate, like hibernate to Lady Michelle, Asia and handler, those you'd be ignored. Do not need to understand those concepts. To do the prod operations. Then will ensure a course id is of type. Begin to our long, because our database ID field is of type big it, it did not create any suits for the select or final operation, but for insert, delete will apply. In short, it's of the same type. Generate the corresponding getter or setter methods are simply update the data type for the course ID field. Back in the controller. Let's add a method to get a specific course. So this method will take a course ID and return the corresponding course. Core repository has different methods to fit specific IDs. By ID. Then we have to capture the request mapping since we'll be dynamically passing the ID. That we can do that is by using curly braces center, capturing some variable inside that. Using the path variable annotation, we can map the ID getting passed in the URL to the method parameter. And using that ID, we can fetch data. Let's run it and see the output. It's trying to build it. It gave some syntax error. Let's fix those. It path variable. We do not need to use the equal sign. Let's sum it again. Okay, so we love to convert the output to a core subject. So there is another method available, gate one ID. So that will directly give us a core subject from the course to positively. Let's use that. So gate one and specify the ID and the corresponding cost object will be returned. Let's run it again. This dynamic RAM fame application is up and running at port 8080. Let's see of courses. You are, it works fine, it does. And now we'll pass specific ID. Let's pass one. And we can see that the fossil record is getting faced. That is the big data HADOOP course bus two. And then you can see the second course is getting phased. And if we try to bison ID, which doesn't exist to give you some exception which can be handled in the application. But for now, let's better understand how could just pass idea and get our data back. Now we'll see the insert operation. So for the insert operation, we need to pass an object to the CPA repositories to there is a safe mentor that would take core subject is a parameter and saved to the database. Instead of get elliptic send a post request to the application. The way to do that is specific to our mid third dot type is pushed and passed through a URL in the value. So we left class courses URL. So that when the URL to post, let's now add a method to do delete operation, like the insert operation, delete operation would not return anything apart from the HTTP status to delete a course. So we'll have to pass the course. Id is a parameter. The way to do that is by using the path variable annotation and specifying them. Method name is delete. We can now one method for insertion and deletion will go and run the application. Got some compilation error. There's a typo here. Let's fix it. Run it again. That is running now, we can pass an ID and see the output are paired with at all courses. Let's not try post. Select the type is pushed to the request. Now look two passages and object in the body. So let's add a new record with course edify and course named Java and somewhat acronym. And Ruby specified though typist Jason application station because you're sending adjacent object. Now send it. Let's see if it got inserted. Gave some error. Let's see what it is. It says IDs of the class must be manually assigned. Yeah, so these two here is, while reading the incoming request, we did not convert that to a core subject. So when you specify a request for the annotation, the JSON object will get converted to a core subject and object will be used by the GP repository. So that is the state that we missed. Let's run it again. We'll now post, post the same object with Coursera. Before. This time we got to a 100 okay, status. Let's go and check it in our database. We can see that the accord with course Eddie for cotton circuit and we can see the query in the logo. You'll add another record. Let's insert course with Coursera D5. Calories also getting circuit. You can change the course m and send it again to see that. But of course template updated. To use the same method could do obtain also. Lets now try or delete for delete with up to select the delete request type. First, let's do a get. We are able to get the course. You'd cos 35, let's not deleted, select, Delete and send. The same request. Will delete an anther record. This time of course ID for and you take him got deleted. 37. Exporting the Application to a JAR File: So we have a course application ready, which connects to the back and get our best. And we are able to do all kind of Travis operation and themselves creating Certainly. Now let's see how to export this project with JAR file, which can be executed in each other in a moment. First, let's stopped application. There's a raid I can hear which you can click and stop running up in Inteligencia Mavin Link. On the right hand side, Select darken Pick on him, which is Executive Mammon Goal and such for Ambien Package, which is the Mavin package manager. So you click on that. It would start leading a jar file off your application. It will download all the required that jar finds have into them all the Springwood, our dependency jars or any other jobs that because it might be using So this file size would be little use around 30 to 48 beat. So you have this future fails, but it'll come in all the jar files called the Target folder, and you can see the Courts up jar file, which got generated not this job condone in any job moment. There's a terminal tab here you can go there and create a new terminal and go to the target for lead. And there you'll see the jar file course up supports a number and Jack stop certain larger now using Java minus jar. You can execute it, and this would run in any environment in on any machine where Charlize there is a self contained application. Some windows, promicin regret. Pop pop. Let's kick Okay, you may not get it in your machine, not Goto Postman and involved the service. It gives a mirror because it's not able to find the good habits so that Travis was under the main course Fulla, and you'll see that it's saying missing that of its because we're running it now with the target for them. Either we can move the religious to the Target folder, or we can run the jar file from the course of four in another environment, deliberate. Sure, the database is set up, and every level of the same directors the project. Now we're running it from the quarter folder and we'll say targets plus the jar file. It will find a job, and you'll also find our database. It the same for Leonard run find this time now wearable DuPage data fits with speaking a guard. Do delete into all kind of operation usually, Joffrey. 38. Integrating services with RestTemplate: Welcome back. Cartel. Now we have built a court's application with a database of its own. And this is a self-contained application that can be deployed in any Java environment. And can we invoked through wrist? Now how do we call this service from another service which is also a wrist web service. For example, how do we call the core sap from a Course Catalog app, which might be needing course information. And further it might be relying on the courts have service. So let's understand that in this lab. Let's go to started Sprint dot IO and create a new project for the course. Catalog hub will use web rest. We do not need the GPA because we not be directly interacting with the database from this Course Catalog app will in turn using the core SAP, which will interact with the database. Let's import the course Cutler project. It'll be of type mountain-like God the project. The app is now ready for us to make changes. So let's see what are the changes required in the course catalog for it to find the course app. So we'll use something called Race template. Let's give a new port to the course catalog apps. Solver.py equal to h 001. That's the port for the course catalogue up. Because the default port 88 is already taken by the courts app. Using application dot properties, you can modify the default port. Now let's create a Java class. We'll name it as catalog controller. And we'll address controller annotation. This class will have methods which will map to rest URL. Let's add a method for homepage. You'll just simply return a string. Welcome to future ex course catalog will annotate it with request mapping. Annotation will point to the home directory. It started it, it's running at port it 01. Let's check it out. Everything looks good. So this is the course catalogue up. Now let's see how we can get data from the course. Let's go to the course app and make one could change show. We'll add a mapping for the different root directory. We have annotation for the courses and for the ID URL, but I think for that we should be blank. Just class sled will point to the root of the application. And we'll return a simple string. This is core Sappho, whom we've already built a home for the course catalogue up for the course tab. Now let's run it. Lord saw the courts have home text list since your other URLs are working fine. Courses should fetch all the courses, send specific courts, IDs should fit particular courts, so it's working fine. Now let's try to integrate the course catalogue with a coarser. Go back to the course catalog project in the catalog controller class. Let's try to append the Coursera homepage messes with the course catalogue up Mrs. now to integrate Buddha Risk Services, we'll use something called Race template. Risk template has a method called get for object, which will return us data from the target tau risks service will have to specify the course up URL, that is the URL that the rich templates should target. The return type would be string dot class. We are going to return the homepage text. It's a simple integration. Using the rich template. Get the homepage message from the core SAP and append it to the Course Catalog app and are displayed. So we're doing that using various templates. Let's run it. So this will be the course app URL, not the course catalog URL which you corrected. Run it. Now. You can see that local or state 001 gives the complete Mrs. part of it from the course catalog and then part of it from the course have. So this is how you can integrate to services using bearish template. We're returning a string from one-day service and using that in the other service. Now let's look at another example. We'll try to return the entire courses list. Clever new URL mapping for catalog. And this should return us all the courses. Will change the URL and then whatever we are getting appended to some string. So our courses are get everything from class courses. Append that to the, our courses hard-coded text message. Let's run it now. And invoke class catalog in the Course Catalog app. And you can see that data getting, getting fades from the course up and getting the split in the catalogue. Now let's try to return an object. We'll add a class called Dog course class, so that we can whatever output we are getting, we can map it to an object and extract value out of it. Even prank that with string. We can copy the entire class from the core SAP and make changes. Let's copy the fields and methods. And we'll remove other database littered annotations because we are not connecting to database from course catalog. It's a simple course class with the same fields and variables, the course up. Now let's see how do return data from a rest service and map it to an object. Let's add a new method which change the URL instead of a string will return an object, the stain. That object would be obtained course. So whenever you are releasing, a core subject would be returned and that same core subject can be used to extract information. Let's change the URL to point it to a specific course. Will try to face the first course. And introduction lingered class now should have Coursera's class in the gate for object method. Return type should be course, and we'll see our first course is to extract the name will change the URL to first course. And then we'll say our first course is whatever cost object we get from that little extra app.get course name. So this is how we can get an object and invoke various methods of it to get more information on specific information. Let's run it. Or it failed because we tried to use the same name for the meter, will change it and run it again. You're going to fail because we tried to any size of course subject to a string. Let says that we'll have course equal nuh course. You can't have Gosling assigned to cluster two is an error. And this time it should run fine. Okay, now let's invoke the first course URL. We can see that Hadoop is getting faced returning a core subject. And from that we are extending the name and displaying it in the course catalog service. So this is how you can integrate the tourists services using the template. Later on in the microservices six, and we'll understand how do we avoid hardcoding. So that'll take us to the world of microservices where the services can be automatically discover and we can also implement other patterns, lake how to handle failure, how to do intelligent routing. So more on that in the microservices Texan. 39. Service Discovery: Welcome back. How do we find a service other than hard-coding the URL? Also, there could be multiple services running with multiple instances. So if we do add coding, it will not be very scalable and manageable. And also how do we manage failure? A service can go down. So there should be a way of knowing whether the services is running or not. Based on that, we should be able to handle failure programatically. So this is where service discovery comes into picture. Services can preregister them, synthetase central server and the resistor when not available. With service discovery can monitor into health check also. So spring cloud Netflix is a very popular project which you can use to implement service discovery. It has two main projects. One is Netflix Eureka server and the other is Netflix Eureka client. So the concept is really simple. You build a discovery server and you register services on that server. And then discovery server acts as a registry for those services. And it will manage the services. It will know when the services are up. They're not so that anybody looking for these services can be given the right response based on the service status. And also you can never hardcoding by looking up services with a certain ID or a certain name. So we'll explore more on this in the practical session. Thank you. 40. Setting up a Eureka Discovery Server: In this lab we are going to get their discovery server using which we will discover different services. Let's go to Start Dart Sprint dot IO will give a package name. And artifact dot project name would be 0 cost server. Keep everything else as default. Bitcoin are dependencies. Search for eureka server. It's a spring cloud Netflix Eureka server. Let's click Generate to download the project. Will allow unzip this file mixed with Lord This project using IntelliJ idea. Let's find that project. It is future ex eureka server. Under this particular Java microservices directory, will select that. It takes a few seconds. Good lord. The required dependencies. At the bottom you can see resolving dependencies for future ex Eureka server. Once that is done, we should be able to see the entire project directory. Now we can see the project structure. Let's load the main Java class. Let's start enable lyrical server annotation. Added automatically includes the required packages. Next will go to application dot properties and give a port to the Utica server. Will make it run at a particular port, but usually that is 8761. For the unicast server. We'll give the up in name. We'll call it a fixed discoveries that were. Next, we'll say registered with the recap faults and fate registry false. We'll be using the discoveries server could discover other services. How what we do not need to register the server with itself. That's where the two properties are set as false. Let's go to bomb dot xml and find the new dependency that Spring Boot has added. So this is the dependencies bring cloud startup, Netflix Eureka server that has been added to this project. With this, we are ready to launch the Eureka server. Let's now start dot, click on the green icon. We gotta Nader for Java Eisleben support because we did not change their default Java. And while creating the project as of January 2021, job Eisleben is their default worsen that springboard has. And now we can go back and select eight embedded at the project. Again, we can upgrade dedicated person in IntelliJ put on Java 11 project. Let's see how to do that. Go to File Project structure. Click on the adjudicate dropdown. Then are the SDK. You can click on download JDK. It will prompt you for the available options. Now it's prompting for open dedicate 15.1. Download. Then apply. The Nokia JDK installation will take a few seconds to finish. Dedicates been upgraded, let's run it now. So now it deletes days using the open dedicated pinpoint 0.01. to run this project. Click on Allow access if prompted. And now we can see a message that future xy record server application has started. We can open a browser and Lord localhost 8761. And we can see the Eureka server Dashboard. We can see some gender Lynn for both the Eureka server and under the stances 6-7, nothing is appearing right now because you have not registered any client with the server. This is how we can set up a discovery server. Next, we'll understand how to register different services with the discovery server. 41. Registering the Course app as a Eureka client: We'll now arctic course and register it on the Eureka server. Earlier we created the discovery server using Netflix unicast subvert dependency for any client. For the Utica server, we would request spring cloud Netflix, Eureka, claimed dependency. Let's go to Start dot spring dot IO and create a new project. Let's call it the future ex. Courses. We learned with risk. Spring data, GPU, Utica, discovery, gland. Let's now Jim did the project. The project Lord, that project quintile EJS file new project from existing source. And let's select that project directory. Then next. And we'll select Open JDK, beam. And finish will open in a new window. Let's add it is it May 1 project. Now the project has been loaded. To make this a eureka client will need to add an annotation enabled Eureka land. Next door. We'll copy the files from the older course, our project. Let's select course, course control law courts repository from the old courts. Our project will copy. Then go do future IQ scores app, which is the new app with you recalculate. These classes under. This package. Would automatically adjust all the packages names for all three classes. Will check the bomb dot XML. So we added does bring data GPA, the rest, and web dependencies. And we all started Netflix Eureka client. If want to make any app, you record Discovery client, you can simply are this dependency and enable Eureka claim. You'd need not create a new project. We also need to add the sequel late, later dependencies from the older project. Let's open the old project. Go to Palm dot xml. We need two copies, circulate JDBC and circulate dialect. To the new project. We have copied the dependencies. Now back in the future, IQ scores have project simply paste. So now we have SQL literate dependencies. In the future X coarser project will also copy the database from the old project, but a new project. So this is the old project course app. I'm copying the future ex courts or database file to the new project. Let's ensure everything looks fine and go to a command prompt. And we'll say sequel light three, future ex courts DB. Now let's check out the table. Here. The data is still intact. To simulate fails can be easily copied from one directory to another. You copied this equality declare dependencies, and the database to the new project. Let's check out the application dot properties. We would also need all the properties that we defined earlier. Let's add them. We'll add a few additional properties. The new core step will give this happened name. Let's call it x core SAP. Handout will also give us separate board. Probably microservices that you're creating. You should have a different port. Now let's go to the main class and run the application. It failed to start. It says could not find our Lord man. Let's delete the main.xml file. Sometimes when you download and upload a project, it creates issues. So you need to delete the old I yml file and then select bomb dot xml May 1 and reload project. And now everything looks good. We'll run it again. Got some error. So the class that we copied did not automatically import all the packages. Click on anything that is highlighted in red and hit enter and all the packages will get deported. We'll check the other class. Everything looks good here. We'll run it again. Now we gotta misses that started future edX Course application. And it also says registering service and registration status is 204. Let's check if dab got registered. And we need to ensure Eureka server is running. So Eureka server is currently running at port 9300. Let's go to Utica server dashboard. And we can see that the future ex core SAP has been registered it port 8,001. So this is how you can register an app on the discovery side were so that other apps can come to the discovery server and find that out. 42. Integrating the Course Catalog app with the Course app through the Eureka server: The lawyer created a discovery server and registered the coarser. Let us now understand how to invoke that course up from the course catalog app. Let's go to start spring dot IO and we'll create a new course catalogue up. And we don't need GPA. We need to keep data card Discovery client. So we raise ten director discovery claim. Let's generate the new app. Now will load this up using intelligent New Project from existing source. And let's find a new course catalog, future ex Course Catalog app. Select their directory and load it. Will select Open JDK 15, will open it in a new window. Let's add this as a Maven project. Let's expand the project. Now we'll copy the course class and catalog controller class from the older Course Catalog app. So this is the old course catalog. Let's copy catalog controller and course dish to classes and pasted into new feature x Course Catalog app project. Let's delete main.xml file and we'll reload my one projects. Now everything appears correctly. Let's hit to catalog controller. Earlier we hardcoded the core SAP URL. So this time we'll use service discovery to find the course up from the course catalog app. But let's make a few changes to the application layer properties will give this up in name spring dot application.rb. And let's call it the fixed catalog service. And we'll make it run at port 80 geologic CO2. And finally we'll say eureka client registered with the lowercase false. We do not need to register the Course Catalog app. We have registered the course app and we'll be discovering that from the catalog, but the Catalog app need not be registered down. Now let's go to catalog controller. So let's comment out the hard coating of the URL. And we learned a eureka client, client, heart enter and you'll get the package name. So Netflix discovery will make a claim that is the client we're going to use to interact with the discovery set well. And we'll make this variable private. We need to create an instance of class instance info. Let's include that. And by saying Eureka, claim, dark get next server from Eureka and specifying the app which you want to discover. And an instance of that particular tab. So this instance info is an instance of a fixed core service which is registered on Eureka. So this is how you can get an instance of one up in another app. Once that is done, you can get the URL up DAP by saying instancing for gate homepage URL. So that would be the Court's up URL. Should these are the changes required. Create an instance info object and then get the URL. So that way you can avoid hardcoding the URL. Course catalog will look for effects core service in Eureka server and find that you are in. Let's make that change in all the methods. Now for this particular method, we need to also append to the URL. And let's add Enable Eureka clan annotation. So this is required to interact with the records that work. Though we are not registering the course catalogue up an app on the eudicots that were. Lets now run it. We've gotten Nadar that URL might not have been initialized. Let's fix this. We need to first get the URL. And then we did we append courses. So now the Course Catalog app is started and it's running at port two. Let's refresh the Utica dashboard. Corn syrup is registered, but course catalog is not registered. But Course Catalog app can discover this future IQ scores up. Let's load the Course Catalog app 88 jealous 0-2. Regarding data, let's check it out. Regarding error that the client is null. We also need to add the auto where'd annotation for the Eureka client. And let's read on it. Now it started again a digital tool. Let's refresh the page. And we again coordinator, let's check it out. It says no matches for the virtual lost FX core service. So we need to ensure this app name is correct. Let's go to future IQ scores up and we can see that it is registered with future ex course up, not FX course up. So let's cut it, this, copy this, and go to a fixed Catalog app and put the right tab name. Now let's restart this. You'd started again a day digitally literate to. So this time it worked fine. We can see the messages coming from the course up. Now let's try to get the first course. And we can see that our first courses Hadoop that is coming from Coursera. Let's shake that catalog URL. And courses are getting fades from the Coursera course app log. You can see that guard invoke Dan messages getting printed to the log. So this is how we can create a eureka discovery server resistor and nap and discovered that app from an adder up. So this is our service discovery works in the Microsoft Word. 43. What happens when the Course app goes down?: Welcome back in the service, Discovery six. And we have seen how to raise history up on the Discovery Server is a Eureka client. Then how to use our Discovery server to look up for that up? So we have a course out, which is letting it Port IV 001 and that is also registered. Eyes a wreck, a client. We can take that it pork 8761 You can see that it is registered and variable toe interact with their top from course catalog, which is running at age two. Now what will happen when the course up goes down? Let's find it out. So what we'll do is we'll go to the course up and shut it down. So let's go to the Porter project can just simply shut down the running application. Now, when you refresh course up, you'll get a never paid because the upper stopped running. When you go to the course, catalog up and try to refresh the home page, which is dependent on the course up if you give us a minute. Also, it is saying this is the fallback because there is nowhere that pace you ever told up what to do in case another app is not available. And I displayed another Pidge. So this is not the ideal situation, because one micro service going down can take down other services also, and there could be hundreds of thousands of micro services running in a production set up. So let's understand what other picnics, every level, the handle, such failures in micro services. Thank you. 44. Handling failure with Circuit Breaker: in the previous love we saw. When the course up goes down, it also takes down the course catalog service in a micro services set up or in any application, failure could happen for many different reasons. That could be system issues that could be network issues, that competitiveness issues, then how we handed those failures so that our application can work seamlessly. One of the popular technique for handling failure in micro services or in any application, is the circuit breaker pattern. So as the name suggest, just break the circuit. So stop sending any additional request to the downstream service. When you would realize that those services down it's really easy toe Implement a circuit breaker in spring clout. It has Netflix history libraries, which was the Lord by the teammate Netflix. Using that you can easily implement circuit breaker. The way it works is pretty simple. Let's say one services in walking another service, and when 50% of the request fail in a 12th rolling window, you just break the circuit. And how do you know when the service is up? Keep sending one request every five second to check the downstream services up so That is the way our Netflix, his tricks circuit breaker, what's and we'll see that in the practical station. And how do you handle that failure? You can have a fallback matter, which can call another service, which can call another matter, using which you can display some misses to the user that the services don't or you can have some ordinates strategy in terms off are displaying that up from a separate Microsoft's is still the main services back. So in the next, love will understand. How do we handle the failure of the course up by calling another fall back method, which will give us some pre configured or hard coded mrs and which you can use to display back to the users till the course up comes in light. So let's see it in action. Thank you. 45. Implementing Circuit Breaker with Netflix Hystrix: we'll come back. Or let's understand how to implement our circuit breaker on the course catalog service so that it can handle any failure in the course up So you can go to the course catalog project and make required changes in the bomber. Excitement are you understand what dependency we, too, are for the sticks ever. Let's download a dummy project from starters Finger. Do you sorry for his streaks. It's currently fundamentalists might be getting phased out. I'm sure a better solution will be provided for circuit breaker with spring clothes, so let's use it for the painting. We just need to see what dependency needs to be our right our to make our course, catalog up a new circuit breaking. Let's open the former XML. We can see that there is a dependency Netflix his tricks. So that's the one we need. Skopje Tender pastry in the Bomber XML In course catalog. Spring Cloud starter. Netflix is streets that's third pregnancy. Now here we need to harder and an impatient for historic circuit breaker sanitation is enable circuit breaker. It takes some time for drought in diligently. Download all the jar finds as soon as you are their dependency. Mammon would look for the required and once the jeffren started intelligible, automatically problem you OAS. Soon as you start typing for interval circuit breaker just started and the classes we get important also. Now let's go to the method which needs to go second. Taking will implement it on the home pitch. So there's a history command 100 patient that regard on Would. It does specify worked fall back method. So let's add a new fallback matter card display, home page or display default home bitch. And whenever there is a connection, failure course up is doubt. Then that would be a fallback matter, and we can return. Some are text from that metal, so that's it. That's the way we implement a circuit breaker. We just put some dummy message. Please try up for some time. So the court sap is running. The Children's is for the course. Upwardly display are the wage. This message will be displayed. We'll check it out shortly. Similarly, you can do it in the other cards also, but let's tried out the homepage now. Just done it. So it restarted. Let's sort of fresh stoppage. You can see that please strap for some time that Mrs getting printed from the point back. It's going to start the course up. No. So when course up is down, the fallback mentor discard When course up is running, it should give us the message from the course up so you can see that. Let's again shut a door and it goes back to the fallback mentor. So that is how you can implement circuit breaker. You can tell one now what to do in case another up is not available. 46. Course Catalog Project - Problem Statement: Welcome back. It's time for the final course project work Till now we build a course catalogue service, and we have pulled information from course up service to rest. Simply now, we need to announce this application is part of the project. What were the user up service with its own database? For each course, you'll find the corresponding indoor leisure information in the user of service. So it's part of this project. You will be building another micro service and integrating both the course of service and use it up service with a course catalog studies. So, given that plan and will be visiting the solution for this project in the subsequent laughs , Thank you. 47. Building the User App: Welcome back or we'll be building a user up in this lab will select Spring Web spring that a J P A rest repository and the uric Our Discovery Clan. Pretty much all the dependencies that we heard in the course up we're selecting here and downloading the Starter project from spring website. Extract the file and loaded too intelligent project from existing search and select the folder, then select May 1. Built all. And while the application is getting loaded, let's create a new red abyss. Will have a future ex user BB and will create a table called Our User, which will have first like User I d. Course. I'd use a name. Very clever Composite primary key Communists and abuser idea in course ideas. Primary keys Because one user content before the same court certain place. Let's insert some dummy records. You can see that the combination of user idea in course I d. Their unique We have four records. Let's try to insert a combination off user Radian cause, and each already exist. You can see that gave her or late so we have the user table ready now and we'll go back to the map and let's look at the job filed. The main job will be large derecha client innovation. And then let's clear the user class so this class will not toe around it. A vestibule user. Now let's are the usual and, er patients for a DB entity. Jason Ignore properties. And then we have a I D. Class sanitation, which is required for a composite key, will come back to compose it. Keeter class later. Let's are the other Fields say it has to master field names. He's already course i D. And there was a name. Whatever name is there in the database makes your same name you're using here. And since we have communities and abuse their idea in course ideas, the primary keys, whoever composite primary key we need to give an innovation on Bodo fills. So let's add idea notation on both user Radian. Corsetti will now make sure all the classes are important. Let's are the default user constructor and we love generate gator and second methods select all three feels let's now are the usual repository class. It needs to extend from the GP repository. So pretty much the same state that we did in the courts up and we'll have user are in Turkey and begin digital type is parameters. And now let's have the controller class. We learned the wrist controller annotation, and let's are them May 3rd also to get all the users, so that would point to the root directory and the return type would be a list of users now , using the usual repository find all we can get. All the records are the order wear down tradition That should be. We can use this method to fetch all users from the database. We'll go to the applications under properties and guard whatever properties we add it to the courts up project. Let's open that and copy all the properties from there and will make the required changes that a first name would be. You should excuse the baby that started. It is that we created for this up and I will give to stop it name. It could be a fixed usual service. And let's use a different port. So this is important. All Microsoft sister, That there one port. Now let's run it. It's notable toe. Find a Nibali record plant. Let's start entering the import. This could be repeated her. So let's run it again and see what else is there. Composite key. Let's give user dark class and see what happens. I'll tell you the solution later, but for your understanding, just think watcher with the trade class that I d. Class I don't it again. Or the usual repositories would be an interface, not class. It's getting that. Run it again. Now it seems to be running. We're diggin failed because it's not able to connect to the database. So let's hard uh, the sequel, Late dependencies will again copied from the courts our project sequel. It very busy and circulate dialect. This true dependence is not to be added to the partner XML than important changes are due order import. We'll run it again. Could fail again. Now let's make the required changes for the composite key. Let's name it is user I D. And we learned user radian course I D, which are part of the composite key to this class. So this is the way GP and hibernate Kwok's. You look to specify class, uh, with the I d class sanitation and that class would have all the fields of the composite keys. Now Children fade it again failed because they usually class must implement. See realizable. Soc Realizable is a concept using is you can convert object to finally former. That's the way the class has been designed without getting too much into the details of it . Now it seems to be learning, though it's notable registered with the record server, that is fine. We can running is a standalone up and directly and walked upto. Sit out. Let's call local law Star Age Original three. We can see that all the user i D End Course I D records are getting face from the database . 48. Querying the User App on a specific field in the User table: Welcome back The previous lab, you saw how to fetch all the records from a table having a composite key. We used the usual repository Final method, which is a JP repository, are method to get all the records and in the course up earlier, we used get one I D method are too quickly on the primary key field, but in this case, we have a composite key in the user table. Use your idea. Of course I d. So let's understand how to quit. You are either use a ready or course idea or, for that matter, on any field. So it is really simple. All you could do is in the GPS positively hard, a new method find by in the Field Name and jpn High Vonette Take care about generating all the back inquiries and functionality required for this Get of this interaction. For example, for user Raby, we can never find by usual ready. Make sure use already matches with the column name and it could take begin Terrorism Parliament because that stuff type and we can get a list of your just back. So that's it. That's the chain that's required. Now we can invoke this function in the controller are to get it after a specific use. Ready? Let's Adam 1/3 with the required annotation, So we simply used positively find babies Radiometer under to get that back. Let's make sure all classes are important and then on it get sued as a commander is not required. Let's fix that on it again. Here. Now you can see that we're able to get up for a specific user ready. He's already won. We can very fend it off all the records on the records with use already one God fetched. Similarly, we can try for user ready to. There is only one user user ready to and were able to face that. But for our project, we need to face users for this wispy course. So let's are another matter for that will say fine by Corsetti. Now this method can take courts, ideas the perimeter and return the list of users coming again. A restructured let's check it out. So when we search for who I didn't do it fetches all the records with courtside Ito. And similarly, for one, it is all the records with course, everyone. So that's all in this lab, you have seen how toe quickly on a specific column. You can try it out on any column in the user table. All you do is decide defined by a column name method in the usual positively interface, which extends the JP repository. Thank you. 49. Enhancing the Course Catalog App to fetch data from the User App: welcome back will finish the project work in this particular lab. So we have a court sap and that we were using up. Now let's understand how to integrate the course cat look with adapts will fetch course information from the coarser and then face corresponding usual information from the usual. So let's start all the ups, of course, of course. Catalog, usual rap and also the unique assault we can see that director server is running a Both courts happened user up, Hardly disturbed. Now this is the U. N. Of the course that it is running fine and also is seldom eureka. Similarly, let's check the user up. That also looks good. Let's set the course catalog up now. Yeah, everything looks good. All four abscess started. Now, when we go to catalog, we see list off all the courses and we have a first course method also, so that gives us the first course. So let's understand how to fit users for this hard, Of course. So you get the course I D. And use that to invoke the user of service. First thing we need to do is create a user class and mapped out. Put up the use Europe service to that class. Let's simply copied from the user happen pasted in their course catalog. Up next will remove all the databases related annotations and imports that is not required that you're gonna live for the course class. We need object class to map out Levi annotation not required in the course. Get low class. Okay, so this looks good now. Now let's go back to the controller. And then we defined a new object Whether you use a glass, Okay, lets to a unica look up our to find an instance of the user up service. You have to give the user up name registered name that we gave in the application, not properties, while building it is a fact. Use your service. So use that and falls because it's a non secret connection. And let's get the home visual and story may use a wrap. You and variable we left in the course I d r. So this, um because we need to face you just for a particular course is the first course subject and we'll get the course I d from that object and simply pass it on to the user in the quality enhanced to use erupt. Okay, records for a specific course 80. I use the rest template and involved The gate for object matured the way we did our here for the course Aries. So it's not really used. A user objector mapped out. But you can try that also, we're simply off fitting all those years and mapping it with string variable and are displaying the key thing we're trying to understand. Here is how to impregnate between the micro services not so much an outer for murder data, but you can definitely give it a try and extract information after mapping the football specific object. It is starting now. We don't need toe restart any of the other services. As you can see, we managed to fetch all the users for the heart of class and display. So this is our be interact with their different micro services. You can try to announce this project for the try to fetch all the users for all the courses and displayed on the website and also tried implement world tolerance for these Arab service. There are various other things you can try, and hopefully this product has given a good overview and you can now get started with Microsoft is Johnny and build more complex application in the real world. Thank you very much. 50. Why externalize Configuration properties?: welcome back in this six and will understand how to externalize the configuration properties. We have seen how to store various configuration parameter in the application or properties fail. But the challenge with that is every time to make it change will have to modify the application, their properties and then restart application. So this will not work in a production set up where we have the entire project in a jar file . You should not be touching the jar file to modify properties. Fine. There are various techniques available to externalize the configuration parameter in the application or property spray. We'll be exploring one such technique in this particular section. Let's look at an example. Imagine we have to micro services, artist service and payment service, and each micro service has its own application their properties, which stores the Microsoft disrespect properties. Now the problem we're trying to address is how to make changes to the configuration parameter without restarting this services. One of the most popular approaches is to use the spring cloud can fix ever, which can act as the central depository and manage all the properties fail. It can manage global properties for all micro services and it can also manage my course of its Pacific property space will understand how spring cloud conflicts over what's with some examples. Spring cloud conflicts ever is like any other Springboard up. It doesn't store the actual date. Other. Today's man is in the back and deposited like it. Sprinkler can fix, however, continuously pulls the git repository or the back and repository and gives the properties file information in memory. We can have Global properties file like a Prisoner Properties file, which would be applicable to all micro services. Are we? Can my customer specific properties fight like artists of his properties are payments of its properties in the get depository and Spring Cloud can fix server. I will keep it tab of all the properties filed at every level in the gate repository and then try to map them to various micro services will understand it for some examples. So let's see it in action. Thank you 51. Setting up a Spring Cloud Config Server with Git: Welcome back. Let's understand how to set up spring cloud config server. Will register it on the Eureka server so that it can be discovered by ardor payment or any other service. Let's first start the Eureka server. It looks started at port 8761. Now let's create the spring cloud config server app. We'll go to Start dot spring dot io. Let's create a new project future ex convicts server. In terms of dependencies, we need config server dependency and also Eureka claim dependency for the config server. Let's generate the project. Extract it. Now let's load the project to intelligent. Once lauded, go to the main application class. Here we need to add an annotation and a bill config server. And this class will get imported because we already have required dependency for the config server. Let's change the port to 8888. And also we'll give it a name, have fixed config server. Next, we let 2 this config server to a back-end Git repository. That's where the configuration file will be stored. And spring cloud config server pool the configuration from the Git repository and service to the clients. We have a good deposit three future ex skill and that there is a Microsoft folder. We'll use this particular repository to map to the spring cloud config server. Become Clone or download, copy the URL, paste it into application dot property spray. You can choose to use your own Git repository, where you can use our git repository per two large able to check in any file. Here. We have our application dot properties fail with two properties, organism name and service welcome message. And then we also have artists, service properties and payment service properties. These two will be for Microsoft is specific properties fail, which we'll discuss more in detail when we tried to integrate different microservices without conflicts over. Now let's run it. It started at port 8888. Nothing is mapped to the root directory. You can specify slash, handoff, property, filename, and class default. That could fit you are the keys and values of application of properties and also on the keys and values a product or service that properties you can see here. Application dot properties will have global properties and those can be overwritten by Microsoft is specific properties. Harder services, just one property service dot welcome.me. So it is also present in the application layer properties. And application dot properties has an additional organization name property. We'll see shortly when Mrs. will get displayed. Similarly, we can see the content up payment as service properties. Fake. It for type a, property values doesn't exist. You'll see by default to the global property file content that is application their properties. Now we have a conflict servers setup which is mapped to properties failed on the GitHub repository. Let's modify the content of this file. We'll save our son to. And let's save, endow upload this file to the GitHub repository, upload files, and let's drag this files and then commit. You can try the same steps in your own GitHub repository, where you can simply point to the files and see the output. Who can. Now we can see that the changes have been updated in the GitHub repository. Now if we refresh this link, you will see were sent to here. So we did not have to restart the conflicts over the conflicts server keeps looking for changes to the backend GitHub repository, and it will automatically pick the latest changes without having to restart it. So this is our spring cloud config server works. And we can just say nibble Discovery client so that it will get registered on recall. So spring cloud config server can work without the recall. So, but in that case, you look to point each micro service to the conflict server URL. We can see that a fixed config server is now registered on the RCA. We have completed sitting up a stream Cloud config server and we have mapped it to a back-end Git repository. Next, we'll try to set up the order and permanent service. And then after that, we'll integrate these services with the spring cloud config server. Thank you. 52. Reading configuration from application.properties: We have set up a spring cloud config server with the backend Git repository. Let's now create the order and payment services. Will go to Start dot spring dot IO. Let's call it effects artist service. And we'll select rest. And we'll add convict client, because this will be client for the config server. And we'll outside you record Discovery client. And Spring Boot actuator will come back to Spring Boot actuator later. It's a project used to monitor the health of the application. Later on, we will understand how we can use at shorter tdo refresh properties file the runtime. So let's download the project with this for dependencies without server payment service with the same for dependencies. Extract water project folders, and plot to intelligence. Let's first import the effects or the service type would be M7. This is the main application class. Let's change the order service port to a digital one. Now we'll add a controller. Create a new class. The controller. Let's start. The risk controller generation will have a method which will return a simple screen and that will be mapped to the root URL with the request to mapping annotation. Let's run. It. Looks fine. Now we'll add two properties. Organization name and service. Welcome, MRS. These are the two properties will have we had the same properties in GitHub repository files, but we'll come back to that later how we'll integrate these apps, widows config server. Now to read the values from the properties file, we can use add value annotation, specified the key name. And with advent of annotation, you can read the values from the properties file, two local variables in the controller class. So we have an organism name and service messes these two fields, which is the values from the properties, will simply concatenate and print these two strings. Before we start. Let's stop the Eureka server and configure server to be sure that we are not interacting with these two components. So stop do Eureka and let's stop conflicts server also. Now we can start the effects or the service. We can see that the values are getting faced from the properties file and getting displayed. So we are able to read the data from application properties, which is a local property file for the orders service. Similarly, let's try it out for the payment service. Load, the payment service project quintile EJ. Let's copy the controller class from the artist service to payment service. We need the exact same code. We'll change the class name to payment controller and the package name will get selected automatically. So this looks fine. We'll modify the application dot properties will copy application dot properties. Content also from the ADA service. Let's change the organism name to a fixed P. And we'll say Hello from payment. And let's also modify the poor to aids reserved to. Now let's run it. Lord localhost 802. So in this lab we've setup the order service and permit service, and we're able to read content from the application.rb file and send it to the requesting client. Next, we'll understand how to integrate order service and permanent service with the spring cloud conflict server. So that instead of reading data from application that.properties file from the local lab will read the data that is stored in the Git repository through the spring cloud config server. Thank you. 53. Integrating Microservices with Spring Cloud Config Server: Welcome back. In this law will integrate order rent payment service with the spring cloud config server using the Eureka discovery server. So let's start the Eureka server. It is running at port 8761 and we can see config server is registered. Let's load the conflicts. Our property file URL, everything looks good. Both order and permanent service URL SAR fetching data from the properties file. Let's now go to effects artist service. We need to add Eureka Discovery client annotation here are enable discovery client, and let's run it. So all you have done is you have restated Eureka server, end spring cloud conflict server. You have not made any changes in the properties file to point to either Eureka server or to the conflicts over because it's all running on the same local environment. So now you can see that it's fitting properties file from 8888, sorter services stretching properties file from the config server. It automatically picked up the config server which is registered on eureka. We did not have to do any code change our configuration change to integrate the two. Let's now have faced a Jewish rho one. We can see that eugenics skill is getting phase now, which is the content up optically centered properties, which is there on the GitHub repository. Now we're not reading from the local application that properties. So it will automatically got integrated with the spring cloud config server and it is pulling the data from the GitHub repository. Let's try it out for the payment service. We can see that for the permanent service also, data is getting faced from the GitHub repository, from the application dot.properties file. We are not facing a tough, hot, specific micro service. It's all coming from the global property span. But we have a different message for service will come as it says, in the order of service properties file and also in the pavement surface properties. By. Next we'll try to fake this specific messages for the harder implement service. So the way it works is the microservices name has to match with the property filename. We were property fell payment service, Sewell up to name the payment services, payment dash service. Spring cloud config server would map them into service properties file with the payment microservices. Similarly, for the order service will up to name it is harder dash service. So that's the change required to point it microservices to specific properties fell on the good depository. Let's start both order and permanent taps. Refresh the page. We can see that data is getting phase from the specific microservices properties file. And from the application dot properties file, we are fetching organism name. Whatever value is there in the Microsoft specific properties file is getting overwritten and application dot.properties file in that good repository is overrating the content in the local application that property space. Let's change the content up ordering payment service again and upload to Git repository, where I changed it to version three, upload and commit. Now spring cloud config server would automatically pick these changes in Detroit display who are symmetry for the orders service inverse and three by the permanent service. So this we had seen earlier also. But let's see, the order and payment apps. It is still displaying the old value was true. So order in payment service are not picking up the changes that we are doing in that good repository. However, if we restart the app, the changes will get reflected. Let's restart both order and payment services and refresh. We can see what countries getting picked now. 54. Refreshing configuration without restarting microservices: Welcome back in this love will understand how to dynamically refresh the changes in the properties file in order and payment service up without restarting them. Let's go to Bombard XML. We are their spring actuator while creating this projects. Now, spring actuator provides an n in point or you are using which we can repress. The changes in the properties fail, so we'll see that in this particular lab now to enable the refresh will have to make two changes. First thing is we have toe expose their in points. We can expose specific Spring Exeter in part, or we can just wear, start and expose all endpoints. We cannot refresh Corp annotation with a *** class which we want to refresh at the wrong time. So we have one controller here will add refresh cope without control class so that when we refresh using the endpoint, the properties that are getting referred in this particular country plus will get refreshed . We'll do that in just with that payment. Cultural arap also are referenced school validation and also exports all endpoints. So these are the changes required for us to refresh the properties, file changes at their own time without restarting that we're using spring actually dependency to achieve this gets run board ABS conflicts, every still running finest. It's facing words and three now because you've restarted the order, order and payment up would also become person three. So this is all fine. Next will make changes to the properties file and see how we can refresh those values in the order and prevent. Our services also will change the worsen toe four in both order and payment service properties fine and commit. These two fights to the get up repository simply applauded and coming Spring cloud configured reflect the changes immediately. As you have seen earlier, you can see worse than four in both order and payment service. Property spell. Now let's refresh order and payment service EPS. It's still showing worse. Country does not picked up that changes. Now let's understand how auto refresh. Using that spring actuator project, we'll go to the post rental. It should as a health important, using which you can see the status of that simply do extra. This last health you can see that it's displaying bowed abs are running to the 1st 3% a post request with empty body using extracted slash refresh you are in and it really water the values which have changed. So in this case, the service not will come back. Mrs. That has changed. So it's showing with that, and it is the first of all, Lou, and you can refresh the page and see worsen. For similarly let's her first of a loop of the payment out to classic shooters. Lots of fresh. It shows the property that has been modified life. Refresh the page. You should she worsen for So we are able toe reflect the changes in both art and parents that it's up without restarting them wherever they achieve it. Using spring a church, the fresh import. If we tried out a fresh again, it will show you no change because you're not modified. The properties fail again. Let's try it out. We'll see bland because we're not mortified anything. So this is how we condone amicably, reflect changes in the properties file in various micro services. Now you can automate thesis tape so that every time we're checking in a file to the gate repository, that shooter, the fresh and party are being book and the changes will get reflected to some rays. We've understood how to manage properties. File using spring cloud conflicts are worried, a central repository. And then we've also seen how to read the property's felt on the Spring Cloud Convict server and use it in various micro services. We have seen Global Properties file an application that properties we should stop global values. And we've also seen a properties file which can store Microsoft specific values. We've also seen out of difference properties file change in various micro services. Thank you. 55. Dynamic Routing using Netflix Zuul: Welcome back. Let's understand some of the other concepts of microservices. Let's see matching with two microservices running at port 80018 thousand to now anybody wants to access this microservices neutrino, the Executive Order it exact port. And in the production setup, there could be hundreds or thousands of microservices running on different machines and running at different ports. Now, do we need to tell the client the exact URL non-exempt port, or is there a better way of discovering the microservices so that the plants did not know the port and URL. And we can easily manage all the access request. The solution to this problem is APA gateway or gateway service. It can act as the single point of entry for all clients. And the gateway service can go and get the exact URL and put up the micro service from the discovery server and server to the end-user. So the end user or the client need not know the individual URL in ports. Gateway service can manage all the requests routing. Apart from doing dynamic Writing, the gateway service takes care of a lot of other functionality like authentication. It can ensure only the legitimate requests per reaching the micro service. It can log though incoming requests for auditing buffers. It can also announce the request and add additional information which can be consumed by the microservices. It can act as a load balancer. It can also invoke different APIs for different clients. For example, if the request is coming from a desktop, then we'll solve one microservices is coming to a mobile device, will serve another, Microsoft, which will return some lightweight data. Let's see an example of Gateway Service will implement getWidth service using something called Netflix June. So let's see that in action, we'll first start the Eureka server. It is already running at port 8761. Now let's go to spring website and we'll create one service, will have just restaurant Eureka client. Download it and we'll add another service. Service two will also rest and yuriga client dependencies for this service. Downloaded. I'm the both the zip files go to IntelliJ and import the project. Let's import service confessed will enable Eureka client annotation. Let's add a controller class will limited service controller will have a simple URL mapping to the homepage. Let's give it a name, a fixed order, and we'll run it at port one. That's where service one would be running. Let's add the controller method will service to another service returned from the homepage. Now let's run it. You can see that it's fetching service one order service. So microservices one is running at port 80, original one and can be accessed at local or state one. Let's import the other service, service to similar steps. We'll enable Eureka client. Let's copy the service controller from service one and we'll make changes in that. Simply copy and paste your pride all these steps earlier in our other modules. Paste it and change the text. Look, let's call it payment service. Service to payment service will run it at a different port. And qualitative experiment, H two is the port for the service. Let's run it. It's running now let's verify. You can see that it's turning at age two. Now let's see how to implement gateway service. Let's add a new project and we'll have only record Discovery client and should cuts the Netflix project that we'll be using for dynamic routing. Simply out of the project. It is like any other springboard project. Will have enabled Jude proxy and will also enable discovery claimed, destroy dependencies. And in the application that properties we can give it a name. So this will also get registered on unica server, will have a fixed gateway service name. And let's run it. Eureka, several good to service order payment history, upset resistor. There is an old apple statistically district. That's fine. Now we can go to each row, you destroy a fixed order, and we can get the output from the order of micro service. Similarly with a fixed desk permit, we can get output from the payment service, gateway service URL available to access both the microservices. This is dynamic routing which will be implemented eating Netflix June project. Thank you. 56. Client side load balancing using Netflix Ribbon: Welcome back. In this lab we are going to understand an input and Microsoft concept called client side load balancing. So why do we need load balancing? Let's imagine we have a Microsoft is, for example, we could have a currency service which might be getting access by multiple other services are external applications. So what will happen when the load increases? It might take lot of time to solve the request or some other kids might get timed out. So how do we solve this? So we can create multiple instances of the same service. For example, we can have multiple instances of currency service running at three different ports or multiple different ports. Then we could add a load balancer which will read all the incoming request, then routed to different instances of the currency service depending on which one is available or it could just work in a round robin fashion. So this is server-side load balancing, where there is an additional hardware involved, there is an additional network hop. All the outside clients, they'll first target the load balancer. The load balancer will target the application which host multiple microservices. Another way of addressing this issue is by doing load balancing at the client side. In that model, there is no intermediate load balancer. The load balancing will be done by the client. Client to know the number of instances that are available for a particular service. And then you could choose which one to go to based on certain logic. It could be on a round robin fashion. And there is no additional hardware involved, and it is handled through programming. We can easily implement client side load balancing using spring cloud, Netflix Riemann liability. Netflix 3-1 has built-in software to do the load balancing. You have already seen Risk template in the previous labs using which we have interacted with two different microservices and springs risk template has the required integration for Netflix riba. Risk template can balance request across multiple instances of a service using rebuttal load balancer client, Netflix RE1 can work. We thought without the Rayleigh server will see the implementation of reward with you record server. By default, the algorithm works on a round robin fashion. So let's look at the practical side of it. Will implement client side load balancing using Netflix ribbon with spring cloud. Let's get started. Go to Start dot string dot IO. Let's create a Microsoft is called currency service will have the eureka client. We'll have Spring Web and reciprocity. And we are going to implement load balancing, Column Width, unicast service discovery. Go to intelligent and import the project. Find the currency service folder and load it. Select membrane. Now go to the main class. Let's add a nebula Eureka client annotation. We now are at a controller. Let's limit as exchange controller. Let's add the required annotation. It will be raised controller. And we've written a simple string because we're going to try load balancing. So we need to let the client know which instance it is accessing. So the best way to do that is by sending the port back. This is just for the demonstration purpose, so that you'll be sure which in stance is returning the string will return the port of this application. We can get the port from the application dot.properties file. There is an adaptation available for that. You are the hat value orientation and you specify the application dot properties for variable, which is somewhat dot port. So let's add that also to the application layer properties. This way you can read any application dot properties configuration parameter. So port stored in port, and then we just simply returning that port when we have multiple instances, which we'll see shortly, we'll know which instances returning the pleasure. It gave a compilation error or it has to be within the class. Let's fix it. Also. We forgot to add the reckless mapping annotation. Let's do that. Again. It gives some metadata because Eureka server is not running. That's okay. So we can see that it is fitting that port number so we know that we're hitting the currencies are reset for digital one. Now let's start the Eureka server. This is the same product that we built earlier. And you just run it. It started running a date 761. All looks good. The app guard registered as an unknown now because we did not give it a name. So let's modify the application dot properties to give y. Since servicer name, we'll call it currency service. With the spring dot application dot name configuration parameter. Let's restart the currency service. You can see the currency service now the unknown is still there. We'll restart the Eureka server than that will go. So let's get started now. Once we started, give it some time for the currency service to get registered. Yeah, now we can see that currency services running at port one. And it is registered on the Eureka sorrow. But also. Now how do we launch another instance of the same service on the same machine? So for that you have to go to edit configuration, run configuration in IntelliJ J. And then there is an option to allow parallel R1 at the top to select that. Then you can run multiple instances of the same AP. Now you change the port. You can change any parameter and run it again. The old one will still cardinal to run, but a new output get lunch at a different port. So now currently services also running at port 80 through you can go to run and stop and stop. Any of these instances are both instances. Now we can see that age is row one is also returning the message and the nature reserve two is also returning the message from a different port. Two instances of the same currency up running. And then both are also registered on now Eureka. But as you can see here, now let's create a currency up which should invoke these instances and which will do the load balancing. We need to add the Netflix F31 project. Apart from that, we need the risk and the record is coded Klein. And what is the most important dependency here, which is required to add all the liabilities in classes required for load balancing. Let's download it and read Lord it to IntelliJ, select currency up, select M7. Let's open it in a new window. So now the app is loaded. Let's add a new controller class. We'll call it currency controller. Let's add the annotation risks controller. Let's have a method map to the root directory and the b lambda rich template declared as a class variable and will auto wear that. And let's add a method to get the rest template. Now let's make the rest template work with the Eureka client by number Discovery client annotation, and will declare guy client variable. The way we have done earlier to connect course catalog with the course and do that up service is the same code. Will declare a client variable at the top or towards it. So with this eureka client handle, we can get an instance of the currency service using the rest template. Same quarter Israel credibly give the currency extends service name, which is currency service, falses word, non-singular. Store the currency exchange URL in a variable. And use that to get the instancing bearish template. We'll say since value is whatever message we are receiving from the currency, sadness. Now this is the most important step, will have been annotation and load balancing annotation. So this will connect with R31 client. This is the only change that is required in the rich template to connect to the client. Let's run it. Let's load a door. And then we can see it is fetching data from two different time instances of the currency service, eight thousand, one hundred and eight thousand, two hundred round-robin fashion. So this is how you use risk template and B31 load balancer plant to implement client side load balancing. So you can have two instances are a hundreds of instances. This will still work. Hollywood producers make the changes shown in the lab, then you are all set. So this is client side load balancing for microservices. Thank you.