Spring Boot Fundamentals: App Configuration With Profiles and Deployment Using Docker | ChargeAhead LLC | Skillshare

Spring Boot Fundamentals: App Configuration With Profiles and Deployment Using Docker

ChargeAhead LLC, Technologist

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
9 Lessons (29m)
    • 1. Course Overview

      1:35
    • 2. Roadmap

      4:45
    • 3. Audience

      0:17
    • 4. Prerequisites

      0:23
    • 5. Tools

      1:03
    • 6. Demo: App overview

      0:26
    • 7. Demo: Spring Profiles

      9:17
    • 8. Demo: Dockerizing our Spring Boot app

      10:13
    • 9. Summary

      1:08

About This Class

Often times we want a different datasource for test then for production, or have a different logging level in different environments. In this course we will see how to use spring profiles to have different code or configuration to kick in for different environments, without having to change the code.

We will see how to specify the profile, dev or prod when starting our spring boot app and see the relevant settings take effect for that environment.

Next we will see how to add the docker maven plugin and run it to dockerize our spring boot app.Once we have dockerized our app we will lanuch multiple instances of our app using docker. We will also see how to specify the profile when running our dockerized app.

Transcripts

1. Course Overview: often times you wonder different leaders sores for test, then for production or have a different logging level in different environments. We will see how to use spring profiles toe have different code or configuration to kick in for different environments without having to change the code. Hello, my name is Bangkok Jane, and welcome to the scores on spring Good fundamentals at configuration, with profiles and deployment using docker. In this course, you will start off talking about who would be the right audience for the scores, prerequisites for them to be most successful and the tools they will need to follow along. He was in profiles. We will see how to have different pieces of code take effect in different environments, said We want to have a certain piece of code take effect when we're in Dave Environment and certain class to be in effect in production, we will see how to do that. We will see how to specify different law configuration in debt worth this prod and finally , how to specify property values for different environments. Then we will specify the profile Dev or prod when starting our spring boot app and see the relevant sittings take effect for that environment. And next we will see how toe aren't doctor moving plug in and run it to Dr Rice Our spring boot app. Once we have got arised over app, we will launch multiple instances off over app using docker. This should be a fun course. Let's get to it. 2. Roadmap: I plan to create a series of courses covering the various aspects Offspring boot and wanted to take a moment to go where the courts roadmap to let him know what is coming and what we will cover in each course. The full scores, springboard fundamentals, basics and getting started. We will introduce spring boot, cover its fundamental concepts, and we'll get started developing applications. We will see how to use spring initialize er rapidly build and run a simple Weber first and then a console application in the next course spring. Good fundamentals Creating a spring embassy app will build a fully functional spring, NBC App for Managing Item Elementary. We will implement the model service controller and view layers to show the items in wintry really use timely for the view layer. We will explain how to integrate third body libraries like Jake Witty, bootstrap, acceptable in our application and refer good model attributes in the view Earlier will also introduce Springboard Death Tools, which makes development investing easy in the next course springboard fundamentals. Connecting to read a base will continue building over AB and corrected toe a back end database using Springer the GP repositories. We'll start with anonymity, database H two and then later switched to my sequel to show how springboard makes it easy to work with religious databases and switch them at ease will create the ad update, delete operations and complete our spring Embassy AB. Creating timely views for adding in the leading along the way will further explore time. Leave template engine In the next course. Springboard fundamentals. Building and consuming arrest based Web services will demonstrate how spring boot makes it easy to create and consume rest services. We will create great dressed endpoints for the items in that invent tree. We'll then see how to consume rest FBI's In our springboard project. We will take the Web layer off our spring remesy app built earlier, and it sort of fetching data from Madrid. Abi's will display the front end consume later from the rest FBI's In the next course Springboard fundamentals. Monitoring health and metrics with actuators will demonstrate springboard actuators. Detroit is a lot of useful health endpoints and metrics right out of the box with zero according, we will show how to expose and enable the health endpoints. We'll see how to implement our own custom health checks and create new endpoints in the course Springboard fundamentals. Improving performance by implementing cashing, we will demonstrate the cashing support. Springboard provides with just a dependency and a few annotations who can be wise and effective cashing strategy for the application. We will first demonstrate the cashing with the fourth cash manager Springwood provides, and the later sparked the provider to read this in the course Springboard fundamentals. Implementing security. We'll see how springboard makes it easy to implement security. Well first demonstrated basic authentication. Well, then switch over App to use Didem is authentication. Springboard actuator Security is now integrated with the main apse security. We'll see how to predict actuator endpoints. We want to talk about the or to support in the course spring. Good fundamentals are configuration with profiles and deployment. Using docker, we will see how to configure or app for different environments like Devon Prawer using spring for files. We'll also see Holder Doc arise our application docker containers provide consistent development, build test and production environments and make running and deploying our APS very easy. I would recommend taking these courses in order, but if your family, with a certain aspect of string boot. You must skip that course and more to the next one. Further, if you just want to take the course for a certain aspect, it should be self sufficient to explain the concept without necessarily having to take the previous ones, though I will always recommend great the previous courses for a better understanding. So following these cities, of course, is you would have a solid conceptual, and it's turning off. The various aspects of this framework rapidly start developing applications and micro services. All right, let's not talk about the audience for the scores. 3. Audience: This course would be useful for Java and spring developers who want to understand spring boot and also for sort for architects who want to understand this powerful free work and how they should apply to their applications. What are the prerequisites to be most successful with scores? 4. Prerequisites: there are not a whole lot of produces its for the scores. The only thing you need is some basic Java knowledge and some basic spring concepts. Even if you do not have a lot of family already with these, don't worry. I will try to explain the concepts along the way, and you should be able to follow along without much difficulty. Let's next talk about the tools you will need to follow this course. 5. Tools: we will have a lot of demos in the scores as a believe that is the best way to learn the tools I would using. The scores are off course. Jama. I would be using open Judy Kay Warren, 11 but you can feel free to use Java or open Judy Kaye versions eight or above on. Most of examples should work for the i. D. E. I would be using Sprinkle Sweet, which is a flavor of eclipse but is highly customized and optimized for spring development . I would be using the version for it is open source and free and comes with a lot of bells and whistles. But I think you would like, however, if your family with and we like to use some other I d like intelligent etcetera, please feel free to do so. We will use spring boot version 2.1 point four for the databases. We will be using my sequel version, 8.0 point 15 You can find the code for the demos in the scores and the falling Got WRL 6. Demo: App overview: here is over spring. Embassy AB were built in our course spring. Good fundamentals. Implementing security when we go to the browser and put the u r L HTTP local host idiot, He's lashing wintry. It shows us a list of items what it is pulling from a back and my secret database. Let's see how to specify and vitamin specific properties for this app using profiles. 7. Demo: Spring Profiles: In this demo, we will create a class which will be executed only when the environment or profile is prod in a class which will be active only in the dev environment. Next, we will configure logging for the Devonport developments by creating copies of the application or properties file for the Devonport development and specifying appropriate properties. We will also see the departing mechanism where, if we do not specify a profile specific property, it'll fall back to the main application or properties file for the value. Next, we will modify our controller to send these values toward timely view so that we can see them taking effect. We will create run configurations using Sprinkle sweet for Devon Prod and run the AB in these profiles to show our changes. Finally, we will show how to specify the profile when running the AB from the command line. All right, let's get right to it first, Let's right click on over Mean package Jews New interface and call it profile specific interface. It just has one mentored get envy. Let's create a new class by right clicking and choosing new glass. Call it broad class, which will take effect when the profile. It's broad or on the prod environment. Let us have this class implement our profile specific interface. Let's on unimplemented methods. Let's have this mental or down the string broad. Now we've warned that this class should only be used when we're running over app in the broader environment. So first market as a component for spring scanning. Next, using the art profile in addition, respectfully profile Dave or prod or whatever name you want to give inside. In this case, we want the component to be used in prod. So let's put fraud hair. Maybe. We also want this to be the Defour choice when no specific profile is specified so that it's also market for the far profile. Let's 60 import there is Create another class. Let's call it deaf class, and this is the one we want to be used only for the Dev environment. Let us make it implement profile. Specific in the face are the unimplemented method. Inside here, there doesn't return the string. Dev Marta is a component and with the arm profile In addition, let us specify death, so the death class will be in effect in the dev environment and the broad class important development. Let's go back to the controller. Let's create a variable of type profile specific interface and call it profiled glass. Let's order Wyatt it. Fix the import so spring will inject death class or broad class based on the profile, which is in effect instead. The method. Let's create a variable envy and retrieve the value from the profile class. Don't get envy. Next. Let's see how to specify different property values for David production. So let's copy application or properties file and paste it. Let's name it application hyphen profile. Limb. So application happened there. Similarly, let's create another one for the broad profile application. Hyphen prod Inside Head even specified different backend database and connection pool properties based on the environment like they were proud. Since I just have wondered a based on my machine, I would not do that. Now let's say we want to specify the debug logging level for Dev and specify a logging file by the name off Dead God log. Let's copy these sittings. Good work for our application Properties file. Let's make the logging level as error and the name of the log file as product lock so we want the appropriate settings in their respective environments. Let's make a common property. May not greeting in application or properties file, which you picked up by both environments and give it a value item. Elementary. Also let us put before values for the logging level, which you won't enter and put a long file name. Let's call default or log Now for the monster that this is working. Let's get the property's value using the art value in addition with the property name within curly braces and dollar sign and get it in the variable named logging file. Similarly, there's get the main not reading value in a very well mean greeting. Let's create a heading variable were we offend the main reading with the environment name and then the log file. This heading variable is added to the model with a variable name heading. Here is our time. Leave Paige items for you, not html, where we're showing the heading variable passed by the model to demonstrate how to indicate with profile a springboard app should use. Let's create a run configuration in which we pass it as give'em argument. So right click and choose run as and then run configuration pick our AMP and upended with broad. We can choose the profile its proper from the drop down all. You can also specify it as jbm argument which is used when we started the amp so hyphen d spring not profiler active as prod. Let's apply it Not agreed. One for Dave, Right Click on the Prod one and choose duplicate. Name it as death profile. Begin to use the debt profile from the drop down or change it as a VM argument. Space figured as a human argument is good enough, and we do not need to specified hair. Let's apply and close. There are several other ways to specify to spring boot like, for instance, in our application or properties file. We can indicate that with spring or profiler active and then the profile or list of profiles, said Devon default comma separated. But I like specifying an external to the core, the one using the VM argument when starting the app space figured in the court, in my opinion, beats the purpose as you have to modify the AB for death and then for prod. First, let's run the product. The product profile so right. Click and choose run as and then run configuration and choosing first the proper profile and choosing run. Go to the browser and put the u. R L http local host a deity slash and wintry. And now we see that it picked the broad class just mark for the product profile and pick the lock file. Property from the amputation Haven't brought Properties file. Let's stop the AB and now right click Jews run as and this time to use the deaf configuration. Let's refresh the browser and see the right depth profile. Flowers and configuration pulled with Dev Lock file is divert log and the common property showing hair as our main grilling item Elementary going to the lock folder. We see our to log files. Definite log and around are clogged. The devil Long is stating profile activist Dave and the product law states Active Profile s broad. Next, they will see how to run this from the command line and specifically profile there. Let's Tom the app right click on the map, choose run as maven and then specify the goal as package. Now it creates a job in this for her. Let's go with a foreigner type Java hyphen jar and then specify the profile as high friendly. Spring, not profile. Start active equal. To prod our John file name, go back to the browser, refresh the page and see the right profile being picked up here. So now we know how to specify different properties and configuration for different environments. He was in profiles. Next, let's see Hotel doctor Raizo rap. 8. Demo: Dockerizing our Spring Boot app: In this demo you will see the doctor move unplugging from Spotify which makes Dr Rising over Springwood app very easy. Our app is linked to a MySQL database running on our local host. However, in Santa Docker Container it'll resolve local host as the Docker container and not the host machine. We will make appropriate changes store app and my sequel so that the Doctor container can resolve the my secret database running on our local machine. We will see how to spawn multiple doctor instances for our app. Finally, we will see how to specify the profile when running our app in the docker container Let's get started. First of all, let's Google Dr Maven plug in springboards part if I and that brings us to this link on good hope for Spotify let's click this if you scroll down we come to this link specify built in for in the palm Let's get this So here is the plug in which you can actually spring boot app to the black in section level modifying some values But this plug in does most of the heavy lifting for DACA rising over app Lets copy this goto our app open the Palmer XML file, scroll down to the bludgeons section and based this plug in here. Let's put diversion as one dr 10.0. Let's give our image a name. Offspring, NBC The base image we want to use is open J. D K 11 hyphen. Jerry Haven't Slim Spring Boot will download this image as a part of building the Docker image for our app. That is it the rest of the properties to locate our jar from the Project Bill directory and then specifying the jar name stays the same if you go to the application or properties file over APP is refering toe, um icicle database running and local host. This will pose a problem from inside the docker container as it would not be able to resolve it. Let's first see the problem in action first, let's open a terminal. I have documents stolen when the next machine. If I do Dr P s. There are no running and dinners. As of now, if I do dr Images also, there are no images to build a docker image. Using this plug in, let's right click on the project. Jews run as may even build and then specify the goal as clean package Docker, Build click, Run! Let me maximize the console. It is now building the image Spring in the sea. It'll download the open J D. K 11 hyphen. Jerry, haven't slim as it is not there already on our machine, they don't know it will take some time. Let me fast forward a little. It has don't ordered the base image and now has added over application jar to the image and then specified the entry point. Our image is bird successfully. Now, if you go to our terminal and do docker images, we will see the open J D K image which it don't ordered and then our spring embassy image. If it did not have an extra minute database, this would have been all and our doctor app would have started just fine. But starting it now well known with successful, let me issue the command Docker Run hyphen I t for interactive with hyphen P. We specified the port mapping mapping port 9998 on the host machine to port 80 80 on the docker container and then our image name Spring Embassy. The doctor engine tries to create a container from our image. But then it feels if he's crawling up, we see the reason is that it is not able to create the energy manager factory as there is a communication link failure. But they were my secret database. The reason for this is that in our application or properties file, we're looking for my sequel running on local host Inside the Docker container, local host will resolve to the docker containers local host and not over host machine. So in Sandy Docker container, instead of refering to local host, we will have to refer to the I p off the host machine. Docker creates a bridge named Dr Zero by default where the doctor host and the doctor containers have an I P address on that bridge to know what I P addresses used for our host from insect docker container. Let us do I f config. And here we see the I P address as once 100 or 17 lord zeroed one. So this is the I p for our host from inside a docker container. So we should modify our application or properties file to look for my sequel at I P once I went to do Lord $17.0 road one so that it would be resolved properly from inside the container. However, we will have to also make changes to make my sequel to Listen to this i p. So let's go to the terminal first, let's stop the my Siegel service by issuing the command service. My sequel Stop Enter Password. Let's No started by issuing the command service. My sequel start hyphen, hyphen buying hyphen. Address as one. Someone to do about $17 0 Not one comma. The I P for the local host 1 $27.00 and one by an address is the address with which you specify my sequel. Where to Listen with my sequel version, aid dot own or 39 above it, sort of specifying just one value. We can specify multiple comma separated values if we need to. Now, our my secret database will also listen on 1 70 dude on $17.01 Let us now give another try . Let's go to run as may even build and specify clean package Docker build click Run Now, This time the bill fails, looking at the error message The reason is that now Host is not allowed to connect to the My secret server, so we need to enable our user Dave User to connect to my sequel from any host. Let's open a terminal. Let us connect to my sequel a typing My sequel, Hyphen You Root And then it's password to enable Dave User to connect to my sequel from any host. Let's create user diffuser. That person, days within single coats, identified my passport. The percent age is the wild card, which can let it connect from any host. Next, let's grant all privileges on all databases, so start our star to our newly created user. Now there's attempt to build again. Let's go to run as may even build and specify Clean package Docker Bird and Run. And this time the bear succeeds. Our John file is created. Let's go back to our terminal and type docker images, and we see what spring embassy image. Let us born an instance off over image by tapping the command docker run half a nightie hyphen B mapping port 9998 on the host machine to port 80 80 on the docker container and then our image name. Spring in the Sea. This time our APP is able to connect to Arm Icicle database on our host machine, and the APP starts up. Test it. Let's open the browser and type is truly be local host. 9998 slash in wintry slash and we see her page, which is rendered by our doc arised app. Let us poem another doctor instance for our app that's open a new terminal and run the doctor Command docker Run hyphen I t happen p mapping this time Port 9999 on the host machine to port 80 80 on our docker container and then our image name Spring Embassy. It starts successfully. Let's go to the browser and type. It should be local host 9999 slash and Wintry slash and we see were Page, which is rendered by the second instance off forward Authorized app. Cool as you can notice that since we have not specified any profile while starting the APP , it uses the default profile for the default profile. We were using the broad class and default out log. We can also specify our profile when running over after Docker. So let me open another terminal window and this time type docker run specifically profile by using the argument hyphen E for environment. Variable spring underscore profiles and escort Active equal to death hyphen idea for interactive mapping. Port nine and 97 on the host machine to port 80 80 on the docker container and then our image name. Spring Embassy. Our APP starts successfully. That's girl A browser and type issue TP local Host nine a 97 slash and wintry slash And it's your page, which is rendered by the third instance off over Doc arised app running under a specific profile. Dev, hopefully this demo gives you a good idea off. Hot Doc arise our Springwood app and specify profiles. But this we have come to an end of the scores. Let me summarize what we talked about. 9. Summary: in this goals. We started off talking about the audience for the scores, prerequisites to be more successful with scores and tools to follow along, We saw how using spring profiles bigger control, which classes are called which property values take effect with appropriate profiles. So this helps us use the same court base and change the behavior appropriately with the appropriate profile specification. We also saw Ho using Docker moving plug in from Spotify. We were able to dock arise over spring boot app. You saw how to connect over ab running and said the doctor container with the my secret database running on the host machine, we launched several instances off of her docker image. Finally, we saw how to specify the profile while running the app from a docker container. With this, we have come to an end off our series of courses on springboard fundamentals. I hope you find these courses useful and gain skills to confidently start building your springboard. APS. I wish you all the best as you apply this knowledge to the products you are working on. Thanks for watching