Home > Software engineering >  Java Spring Boot Hibernate, JPA, MVC, REST confusion
Java Spring Boot Hibernate, JPA, MVC, REST confusion

Time:10-28

I'm learning Java SE and Spring Boot for a half year now, and watched different courses, and they teaching different ways, and I'm just confused which one does what?

In one course, we're using Eclipse, Spring MVC and Hibernate with MySQL, and writing everything like Servlet, Hibernate configure file, factory, session, and it's just a bit complicated how to do a query for example. In the other course, we're using Spring Initializr, Maven, REST API with PostgreSQL, and it's so much easier, we implementing CRUD repository, and just one line, we can do the query.

And I'm lost at this point. These what I just mention, what exactly we use them for? Why we don't use the simple way in the first course? What we done in the second that I don't have to create a factory and a session to do a simple query?

Is there any post, video or anything about this, for me to understand it?

CodePudding user response:

There are always different ways to solve the same problem. Spring Boot offers you a lot of features to simplify your development. But you don't have to use them. You can always try to implement stuff by yourself. But most of the time, the built in features like the CRUD repository are sufficient to solve your problem. I can't tell you the exact reasons, why the author of the first course did it this way. Maybe he or she wanted to show the principles, that are hidden beneath the features. Maybe it is just an older course or it is for Spring and not Spring Boot. Spring Boot simplified the setup for Spring and made many advancements.

CodePudding user response:

There are multiple frameworks or libraries which comes with its own advantage and disadvantages, however you need to choose the TechStack that suits your perticular application's requirements.

So if you need to build a webapp you can use Java Servlet ,but you have to handles multiple concerns yourself and it involves lot of configuration , but there are many frameworks like Spring,Struts,etc which makes the take easy

Similar way you can manually manage dependencies or you can use Maven or gradle to handle the dependencies and building process

Similar way if you need to connect to a Database you can directly use JDBC but there ar multiple ORM(Object Relational Mappers) available which will make the task easier like Hibernate, Jooq, etc

Regarding your question there is Spring framework and also SpringBoot , main motto of Springboot is that it prefers "conventions over configuration" meaning you only need to write very little code to get started and it comes with many starter-packs which basically are pretty much preconfigured, so you can build application easily

Different frameworks and libraries comes with its own learning curve but they reduce the time required for configuration and troubleshooting

CodePudding user response:

Java EE, Spring and Springboot are not the same.

Spring is based on Java EE. Spring boot is an 'extension' of Spring, especially with auto-configuration.

CodePudding user response:

Spring Framework has been there for a really long time, the ways you have seen are both valid ways, and as far as I understood by your statements is, one way is working with Spring MVC and the second is working with spring boot and spring boot makes things really easy. You need to understand the difference between the spring MVC framework and spring-boot. In spring MVC Framework we manage things with configuration files, like XML files and we also fire queries by opening a session first, and then only we can query. But in Spring-boot these things happens behind the scene and that is why it becomes so easy to work with spring-boot but anyhow we still need to understand all this stuff to be able to work properly with this framework.

Spring MVC is a complete HTTP-oriented MVC framework managed by the Spring Framework and based in Servlets. It would be equivalent to JSF in the JavaEE stack. The most popular elements in it are classes annotated with @Controller, where you implement methods you can access using different HTTP requests. It has an equivalent @RestController to implement REST-based APIs.

Spring boot is a utility for setting up applications quickly, offering an out-of-the-box configuration in order to build Spring-powered applications. As you may know, Spring integrates a wide range of different modules under its umbrella, as spring-core, spring-data, spring-web (which includes Spring MVC, by the way), and so on. With this tool, you can tell Spring how many of them to use and you'll get a fast setup for them (you are allowed to change it by yourself later on).

Spring boot is just an auto-configuration tool. Spring MVC is a web framework

Spring boot = Spring MVC Auto Configuration(Don't need to write xml file for configurations) Server(You can have embedded server).

  • Related