Multi-Module Project With Spring Boot | Maven | Example | Java Techie

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to Java techie in this tutorial we'll discuss how to create multimodal project using Springwood application so we for jump to the code we should know the need of this multimodal project isn't it so as usual let's consider on each case to understand more about this multimodal project so let's assume I want to develop one Hospital management system okay so for that what I need to do I need to write couple of services let's say I wrote doctor services SN services diagnosis services and billing services so if you observe this approach looks good right then why we need multi model project approach so to understand that we need to find out disadvantages in our traditional approach okay so the first disadvantages I can say the code reusability let's say from billing service I want to use couple of class inductor services so in such case as both are separate project I need to copy paste those class inductor services sample if from diagnosis services I want to use couple of class inpatient services then I need to again copy/paste those class I can't reuse those class instead of I am doing here code duplication isn't it and the second problem let's consider in my production server doctor service getting failed ok and I know the fix it is getting filled in now layer or in repository layer ok so to fix that issue again I need to rebuild doctor service and again I need to push it to the production server so we can optimize it like I can create separate repository model or separate service model so if the issue is in repository model then I can fix that and I can redeploy that particular model instead of entire doctor services ok so similarly we can consider one more disadvantages let's say I have some common generic notification service ok so who will take the responsibility to send a notification to multiple easier so if I want to use that particular notification service in doctor service or diagnosis service then I need to do the rest call to that particular service isn't it so always doing the rest call is not a good hapless instead of doing that restive PA call we can make that up service is generic and we can we should reuse it that's what the problem in our traditional approach so now let's understand how we can overcome these three issue using our multimodal project okay so this is what the disadvantages we discuss reusability maintainability and unnecessary with service call okay so to overcome that issue we can go through the multi-modal approach where we can keep one as a parent model and we can write a service model and we can write a controller model and I can write a repository model so whatever the application I have in my project although service layer I can keep in the service module similarly all the controller classes I can keep this in controller model and for repository also I can keep all the repository in this repository model so in future if I need to use particular repository module to the service model I can add this repository model as a dependency in these services okay and the second thing if I found something the issue is in controller model so I can do change in this controller model and I can build this particular model instead of build my entire project isn't it so this this is the typical architecture of multi model project where we should have one parent module and inside the parent module we need to add multiple modules based on our business okay so we'll understand more about this multi model project once we'll start the development okay so let's get started [Music] so going forward let's use this IntelliJ ID for all our Java development so let's quickly create a multi-modal project here click on file new then click on project then click on the spring assistant it will generate the springboard project so click on next then you need to give your group ID and artifact ID all these top ok so let me give the group ID comm dot Java tricky then application name I will give hospital management system and then I need to choose the project type as novel form because this is what I want to generate as my parent model and then I can give the project name here same as my hospital management system so give some description demo project per Springwood multi model application similarly you can change the package here so I'll give the root package as combed or Java techie ok now click on this next so let's add the required dependency I am going to add Lombok and I want toured with dependency which will be spring with then we want JP here then we want in-memory database which will be h2 fine so all the dependents we added now click on next click on finish and I want to open it in a new window so click on new window then let me minimize this top yeah so if you loop in this project we can see only palm not XML right but from this palm that XML you don't have any yes sir see or any resource folder so let's go into this palm nut XML we can see all the dependency which you are read write that as ap then wave Lombok and its to database all right now let's create the module so let's say for domain I will create a domain model for service I will create a service model so let's create that now click on new click on this model now choose the Maven project ok then click on next then let me give the artefact name as domain where I can keep all my entity class ok or I can keep my DT or Bo business object all the stuff here ok now click on next click on finish so enable this auto import now similarly let us create another model click on new model so let me give the name as service okay so all the service classes I can keep inside this service module click on next click on finish similarly let's create our repository ok so click on next add here that if your third repository click on next then finish then one more we want word which will be our controller ok click on model next then add the defectors controller or we can give the name as wave okay click on next finish so we created domain module where I can keep all the entity similarly we created repository module where we can keep our all Dao layer similarly for service and for with ok and let's add one one module here let's give the name as email one so click on this module click Next so give name something like email click on next and finish it now if you observe this hospital management system is my parent module and all the domain email repository service and wave is my sub model so I want to make all the sub module as individual jar so that if the issue is in domain module or issue is in service module I can fix that particular module and I can build it the production right so to make it individual wire or jar we need to set the packaging mode here so the packaging is jar so let's add the same in all the sub-module let's go to our repository and add it here similarly for service for wave and for our email right fine now let's close all the pin pondered XML now let's add the business in our each module so let's first go to domain so if you go into a domain you can find the entire project structure it sets the main taste if we go inside main you'll find Java and resource okay so let's create package here comm dot Java ticky dot model okay then insert this model if you go to select we have doctor patient diagnosis and building right and it worked all the model layer for doctor model patient model and diagnosis like that okay so based on that we need to build our package structure first so add a new package model dot something like doctor okay let me save this click OK now let's add something like a patient model so change it to a sent similarly you can add all other model you cannot building you cannot diagnosis so let's add only two to show you the multi-modal approach okay so now go to the doctor add the entity class here let us give the name dr. so in dr. let me add couple of field private in ID then private string name private string what I can specify here specialist okay okay so as you added Lombok we don't need to write later sitter you just use the an additional data and we want all argument constructor we want no argument constructor then our to string and make this as entity okay yeah and this should be the primary key fine so we created the model similarly you can create your patient model inside the domain model and you can create your diagnosis all this top which we have been our architecture diagram okay so we created domain now let's go on let us create the repository here okay so similarly what we can do I need to create a package come dot Java take it out you can switch world au dot doctor okay and similarly you cannot a send here create a package you can switch word out dot they sent so if you object in the repository we added dr. repository we added person repository and you can our diagnosis repository and building repository okay so let me create the repository for doctor so create a interface let's make it class then we can give the name something like doctor repository and extends it from the PI repository give the model here the model is doctor so if you observe this doctor class is not visible to this repository model right so to access the doctor field in this repository what we need to do we need to add this domain as a dependency in this repository model so go to pom dot xml adhere dependencies then specify the dependency here keep the artifact ideas domain so we can add control space yeah then group ideas dot Java Tiki it should out of a bullet but something going wrong in my idea right so now if you will go to this doctor repository now if you type doctor you can see it here right at the doctor and give the primary key which will be our integer yeah so we created repository now now go to these service and let's create our services for doctor for patient and for all other models so create a package here combed out divert a key note service not doctor click OK similarly create package for our patient now inductor service unit to our doctor service related logic but in doctor service we need to access this repository right so to access it from services what we can do go to pom dot XML and we need to add here repository as a dependency okay so our the dependency here dependencies then our the dependency and specified like repository okay so give the proper name yep you can find it here then go go to our group ID you can find condor Java ticking so let me add it here hard control space yeah we can see the repository here right now go to your that case go to doctor create a class doctor services so annotate this with are the red service now we need to inject the repository right private doctor repository as we added doctor repository as a dependency in service we can able to see this class ok so had it injected using auto add yeah now let's read some logic here to what you can do to get all the doctor okay so first to get I need to add couple of doctor but I can do public word in it doctor I want to initialize couple of doctor so what we can do and let's add this as at the red post construct and let's call this repository dot save all and create least abductor here okay so what I can do I will you stream here yeah stream of new doctor so the IDS let us keep something like 1 0 1 then name give something like John and then give the specialist - ok something like cardiac something like that ok so let's add one more doctor object let me copy this it's giving error because we need to convert it to - list now let's add one more doctor here let's add comma and give the ID - - name Peter give the speciality something like I specialist ok fine so we added - doctor object so let me split this so that we can see it in proper format okay so let me add the semicolon here yeah now let us write a method we will fetch list of doctor object and it will written be a pure controller so public list of specify the generic doctor okay so specify gate doctor something like that now return repository dot finder yeah so we are done with our service now let's go to our wave will write our controller so I am adding only related to dr. similar way I created separate package for patient so you can add your patient service and in repository can add face in repository so I am just to show you demo I am creating one of them okay so now let's go to our width and let's create our controller so first let me create a package new package comb dot Java take e dot controller okay so specify the name doctor controller then similarly create for patient okay now in doctor pulled on just create a class called doctor controller and annotate this with Arthur at traced controller and to access this service inside this wave will need to add these service as dependents in this wave model isn't it so go to palm dot XML are the dependency give the dependency structure at the artifact ID here a service then specify the group ID has come dot Java techie it should suggest yeah now save it now let me close all these open file now go to your controller so in controller what we need to do we need to inject the service private doctor service then service inject using auto it alright so one here let's try to understand point public let's say it will return a list of doctor method name something like get the doors okay and I will return it from surveys dot great doctors okay and hundred this week get mapping give the URL something like doctors okay so this is what the web application and to run this application we need our spring boat main class right so what I can do I'll write that insert this web component so create a Java class something like hospital management system application so undertake this class with at the red spring boot application and it were the main method here we need to write spring application daughter on and give the application class name right it's a misapplication dot plus that's it now this is a whatever main application right so this is what the main class and to run this application we need web dependence isn't it so what we can do go to our parent form where we already added the dependency so let me copy the same dependency control C then let me add it in our whip Omnitech XML okay so let me add it here yeah now go to our HMS application so here we need to enable components can because we are not following the structure that we are using multi modal project so components can give them this package here so what I can give we can specify the comma dot Java ticking which will be our route name right calm down never take a dot star so similarly we need to enable the entity scan because in our domain we are writing multiple entity right so into this can same give the base package let me copy this if the base package is here add it here similarly what we need to do we need to enable the Jaypee repository right so here also we need to provide the root package right so give the base packages and add it here copy paste yeah so we enabled components can we enable entity scan and we enable DP repository as my all the package structure start from comm dot Java techie then I'm giving this as my route packets okay so now we can run this application okay so before run this application let's add its to console let's enable it so that we can see the browser what are the data present in our in memory database so what I can do I will create one folder here let's say the name file application dot properties okay so here I need to enable des it's to console right so the key string it's too dot console dot enable okay and specified true now save it now let's go to our main class now let's run this application run this HMS application so let me open the console yeah so if you observe application is up on port 0 8 0 now let's go to browser to see though it's to console database input so localhost:8080 slash it's to console yeah click on connect we have the doctor table right now run this script yeah we have to record 1 0 1 1 0 2 name John and Peter so now let's go to browser once open a new tab type localhost:8080 / doctors yeah we can able to see the to record right which we added in our in memory database using order it post construct an addition so it looks good we converted our traditional approach to multi model operas and we were able to access our application right so if you go to our core let me minimize this console yeah so we have web service repository email domain right now let us say in service or this email I want to use in this service so simply what I can do I will add this email as a dependents in this service so this email I can make it as generic so that whatever the service I have let us say in service I have doctors are visited in doctor service I can use the same email application if inpatient service there is some requirement to send notification I can again reuse the same email right so let's do one thing to show the reusability what I can do let's go to this email and let me create a package here so you're not getting the package option here so what I can do let me delete this application okay then I will create a new one click right click then you module click on next so give something like email up click next finish yeah so again are the packaging mode here your friend now go to this email app main yeah now we are getting the structure red Java resource so click on new specify the package here something like home dot Java take a dot mail service yeah so here you can create a class email sorry something like that so I noted this width or the red service and simply I just will write the public method to show you that we can reuse the same functionality okay say and email so we should make this application or this email service a generic grade so that any type of argument any model can pass and they can access it so what I can do I will simply print something email service working something like that okay now save it so this email service I want to access it from this doctor service so what we need to do go to the pondered XML and add that email EPS dependency here right so what they can do dependency in artifact ID we need to specify email up and go to this group ID type comm dot Java techie yeah friend now save it go to your service go to your Java doctor module doctor services so here what we can do we'll simply add one we need to inject the email service here right private email service service yeah injecting auto add and simply from this good doctors method I will call service dot send email right so that in console we can see the message which will get from the same email right now if I need same email feature to use in patient service I can simply inject that and I can reuse it similarly whatever the service or whatever the model we have just inject that particular dependency or particular module just reuse it now let's run our application one second let me stop this yeah let me start the application it is building all the model you can see here person Java web yeah it started so if you observe application is upon port 0 now once again go to browser let me refresh this we can see the to record here and if we will go to the console let me go down you should get a email service working great so now this email service I can access across my application so wherever I need to access that email service simply need to add that email API as a dependency and I can reuse the way we did in this dr service read so if a sensor visited again ii need to inject that email service and he can reuse the code yeah so this is how we can work on multi model project in real time i found in maximum project people are using this multi modular approach that's why I prepared this content hope you guys will enjoy it that's all about this particular video guys thanks for watching this video meet you soon with a new concert
Info
Channel: Java Techie
Views: 120,230
Rating: undefined out of 5
Keywords: spring boot multi module project, maven multi module, spring boot, javatechie, multi module project, multi module spring boot
Id: DG9B2w-N42s
Channel Id: undefined
Length: 30min 8sec (1808 seconds)
Published: Mon Oct 07 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.