Step 6 : Spring Boot vs Spring vs Spring MVC

in28Minutes Official
A free video tutorial from in28Minutes Official
DevOps, Azure, GCP, Docker, Kubernetes, Java & Spring Boot
4.5 instructor rating • 47 courses • 725,472 students

Learn more from the full course

Master Hibernate and JPA with Spring Boot in 100 Steps

Learn Hibernate, JPA (Java Persistence API) and Spring Data JPA using Spring and Spring Boot

13:03:24 of on-demand video • Updated June 2021

  • You will learn the basics of JPA and Hibernate - Entities, Relationships, Inheritance Mappings and Annotations
  • You will understand approaches to querying data using JPA and Hibernate - JPQL, Criteria API and Native Queries
  • You will understand JPA and Hibernate Relationships in depth - One to One, Many to One and Many to Many
  • You will use a variety of Spring Boot Starters - Spring Boot Starter Web, Starter Data Jpa, Starter Test
  • You will learn the basic of performance tuning your JPA application with Hibernate - Solve N+1 Queries Issue
  • You will learn the basics of caching - First Level Cache and Second Level Cache with EhCache
  • You will understand the basics of Spring Data JPA and Spring Data REST
English Until now, we looked at some of the basics of Spring Boot. And before we go any further, I think it would be great if you can clearly separate what are the differences between Spring, Spring MVC and Spring Boot. I think having great clarity on that would be really wonderful. Spring Boot, Spring MVC and Spring. How do they compare? That's basically what we would want to answer in this specific step. Actually, by the end of this, you would understand that Spring, Spring MVC and Spring Boot have their own roles. They are not really competing for the same space. They solve really different problems and they solve them really really well. So what's the core problem that Spring framework solves? Think about it. The core problem Spring framework solves is testability. If you don't define proper dependencies then your applications are not testable. The most important feature is dependency injection. The core of Spring framework is the IOC - inversion of control. Spring framework takes control of all the beans and their dependencies. That's basically what the Spring framework cares about. Spring framework is all about defining your beans, putting your at component, putting your at service and things like that and also defining your dependencies at auto wired and things like that and also defining how to find your beans. Components scan for example. That’s basically the core problem that Spring framework solves. Spring framework solves the problem of dependency injection. It helps you to build loosely coupled applications. Loosely coupled applications can be easily unit tested. If you look at this example, you'll see that welcome service instance is directly created in here. This is tightly coupled. The welcome controller is now tightly coupled to the welcome service. However, if you do Dependency Injection properly then you would auto wire it in. You can use frameworks like Mockito and Mock Spring MVC to replace this service with a mock and unit test this controller. That’s the main problem that Spring framework solves. Other than that, Spring framework also solves a few other problems like duplication and that's basically plumbing code. So if, let’s say you are using JDBC then you needed to write a lot of boilerplate code. Try, catch, exception and all that kind of stuff. That's not needed when you use any of the things that are based on the Spring frameworks, Spring JDBC or Spring JMS. You don't really need to do that kind of stuff at all. The other thing with Spring framework solves was providing good integration with other frameworks. So Spring had good integration with Hibernate ORM. iBatis for object mapping. It has good integration with JUnit and Mockito as well. Spring MVC is concerned with developing web applications. Spring MVC provides a simple way of developing web applications. One of the great thing about Spring MVC is the separation of concerns. Dispatchers servlet is concerned with just the basic front controller part. There is a model and view. There is a view resolver which is concerned just with resolving a view name to the physical view. With this kind of simple concepts, Spring MVC makes it very very easy to develop your web applications as well as your RESTful services. Whether you are developing web applications or REST services with Spring Boot, internally you are using Spring MVC framework. That's the Spring web MVC framework. Why do we need Spring Boot? That we have talked a lot about in this specific course. So in the last few steps we saw the need for Spring Boot, right? We don't want to be configuring things like that. We are configuring views resolver, we configuring dispatcher servlet. If we're using Hibernate JPA we need to configure datasource, entity manager and transaction manager and lot of that kind of stuff. Spring Boot says, “OK!” Why do you need to do all this configuration? Can we really think different? The thinking of Spring Boot is, OK! This guy has added a Spring MVC jar, so can I configure some of the beans automatically? Can I configure a dispatcher servlet automatically for you? Can I configure view resolver automatically for you? Can I configure a data source. If the hibernate jar is on the classpath. I know, he put Hibernate jar in the class because he wants to talk to database. Why don't I automatically create a datasource? So that’s what Spring Boot does. The auto configuration part. It looks at frameworks which are available on the classpath and provide automatic configuration. This starter projects are all built around well known patterns. We will talk about Spring Boot starter web and Spring Boot starter JPA in the next step. Other than starters the important goals of Spring Boot is to provide a few monitoring features. So it also provides starters like Spring Boot starter actuator which is used for monitoring. So it enables monitoring for you application and also it has starters to pick different embedded servlet containers. And it has starters for logging so if you want to use log4J, there's a separate logging for it as well. I hope this video helped you to understand the difference between Spring, Spring MVC and Spring Boot. In the next step, we would focus on starters.