PJavorek89 / mySpringPetClinic

0 stars 0 forks source link

Create Multi-Module Project for Data Model #1

Closed PJavorek89 closed 3 years ago

PJavorek89 commented 3 years ago

Multimodule created More info: copy from udemy:

------------------------------------------------------------- Ok, I'm confused. I was following, more specifically copy/pasting the steps. But the question eating me brain all this video: "What are we doing and why?" Basically if I'm at work and getting a project, how I'm going to come to this point to do these steps and copy some details from this pom to there with that structure. Is there any documentation for that? My guess is, we're tying to structure our project and separate Data from web which going to be presented to the client, as this is suppose to be like a real world project. So till the part that we created two modules DATA and WEB, I understand. But from there and editing and copying pom.xml details, I have no clue what I was doing and how I have to do that for another real project. Kindly consider to help me with this and answer my question, as I'm making a great progress with this course so far and this was the only time that I was not knowing or learning what we're doing, since this course is amazingly about understanding and not just copy/pasting. Thanks in advance and look forward to your explanation :) 5 replies SS ------------------------------------------------------------------------------------------------------------- 3 upvotes 1 year ago One of the things that you would continuously keep doing in projects is refactoring. And that is what John demonstrated. Initially, there was one module and all dependencies were present in one pom.xml file. John then refactored the application into two modules (web and data - which as you mentioned you have understood). Now web module has its own set of dependencies and the same goes for data module. At this point, John did the copy-paste from the original pom to the respective modules (web and data, based on what they require). When you would be in a project and need to do refactoring - say breaking it into smaller modules - or even say microservices, you would be in a position to determine what are the dependencies required for your modules. And accordingly, you will go about setting them up. I suggest you rewatch the lesson and things will get more clear now. Hope this helps. Mehran 2 upvotes 1 year ago ---------------------------------------------------------------------------------------------------------------------------- Oh, I see now. So if we want structure our project ie: Data in this case which is going to be like (CRUD) the data from db, i need to be ware of the related dependencies like: mysql, jpa, h2 ... or as for other module Web dependencies like: devtools, web, actuator ... . Now the only tricky part(for me) to understand is repackaging, the one that we used a dependency of another module in another module I guess. Is that part should be done in a specific structure or format? In which cases we need to basically repackage? true org.springframework.boot spring-boot-maven-plugin repackage true SS ----------------------------------------------------------------------------------------------------------------------------- 5 upvotes 1 year ago Now the only tricky part(for me) to understand is repackaging, the one that we used a dependency of another module in another module I guess. Is that part should be done in a specific structure or format? When you package a Spring Boot application (WEB), it creates a FAT JAR, also known as Uber JAR. It contains all your dependencies and also the embedded Tomcat. So when you run the Fat JAR, Tomcat starts and your application is ready to serve request. Now your data module doesn't need to be a FAT JAR. It should be a traditional JAR that the Web module needs as a dependency. That's why you do true AU ------------------------------------------------------------------------------------------------------------------------------ 1 upvote 1 year ago I was having the same doubt, Thanks Sam for clearing this up. Below is my finding with your answer: If we don't skip repackaging, data jar will be considered as FAT jar or a separate project within itself. Which tomcat will internally try to run as a separate spring boot project. Since we don't have main class in data layer it will throw us an error. If we skip repackaging, data jar will be considered as normal jar. Will it contain dependencies or not? If not how the dependencies will be added? Is it the job of web jar to add dependencies of data jar? As we have added a dependency of data layer in web layer? SS ------------------------------------------------------------------------------------------------------------------------------- 3 upvotes 1 year ago The project dependency will be there. Let's first understand the maven package goal and spring-boot:repackage goal. In a SpringBoot application, when you do mvn package, two things happens. maven package goal executes and creates a tarditional JAR/WAR archive that you can deploy on a container/server. Any dependencies with provided scope is not included in the archive. This is followed by the spring-boot:repackage goal. This will repackage the existing archive to allow it to be launced from the console. For that the goal will specify the main class and make it executable using an embedded container. The goal will also additionaly package the dependencies even with the provided scope. If you look in your target folder, by default, you will find two JARs. Re packaging creates new jar file and renames the old one to jar.original In the context of the pet-clinic example, as we don't want pet-clinic-data to be launched from console, we specified repackage to be skipped.