Spring Boot and Spring MVC are actually frameworks or not? - spring

I know that the Spring Framework is a Framework, but the emergence of Spring Boot and Spring MVC makes me confused whether it is a framework or just one of the modules that Spring Framework has?

Yes.Spring is the most popular application framework for develop java base web application and spring framework core feature can be use any java application.
Also many people refer to Spring web MVC as a framework.
There is nothing wrong with that.
In other words, the spring web MVC is a part of the spring framework that is designed to implement web part in our application.
spring framework img
The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for uploading files.
Spring Boot Framework is widely used to develop REST APIs
If analyzed in depth Spring Boot is a project that is built on the top of the Spring Framework. It provides an easier and faster way to set up, configure, and run both simple and web-based applications.
In short, Spring Boot is the combination of Spring Framework and Embedded Servers.
spring boot img
read more Web MVC
read more Spring boot

Related

Expose Spring REST endpoint from Play Framework application

I'm looking for a gradual approach to move a large application from the Play Framework to a Spring Boot application.
So far I've managed to integrate Dependency Injection of both Guice and Spring using the project spring-guice.
Now I'm looking for a way to hook my newly introduced Spring RestController into the routing of my application by means of wrapping it in a Play controller. Unfortunately, the Play Framework does not convert from or to HttpServletRequest since version 2.
Is it feasible at all? Does either Spring Boot support a way to do manual routing to certain controllers or does a current version of Play Framework support any integration with Spring Web?

is spring boot only for building rest api?

and if not what are more things that we can do with spring boot?
i know that we can build a whole web app(frontend and backend) in one spring boot application in the folder resource/template and resource/static but in the real world does somebody uses this method to create web application with the resource/template and resource/static?
and one more question what is used in the real world hibernate(with the SessionFactory or EntityManager) or JpaRepository in the spring data jpa?
No Spring Boot isn't just for REST APIs.
Spring Boot is "just" a mechanism for autoconfiguring a Spring Framework based application.
Therefore you can use and it does get used for all kinds of stuff.
REST APIs for webservices
Full web application using Spring MVC
SOAP services (or are they called SOAP dispensers?)
Reactive web applications
Command line tools
Batch jobs
Swing / JavaFX applications
...
Of course there are many more people writing web applications than Swing applications with or without Spring.
The kind of web application you describe and which I put under "Full web application using Spring MVC" is a very well established model and when done right way better aligned with the principles of REST than the average so called REST service. My very personal guess is: They will still be around when nobody remembers what Angular is.
For your additional question:
Your question sounds a little like the relation between JPA and Spring Data JPA might not be completely clear.
(see Spring Data JDBC / Spring Data JPA vs Hibernate)
Both are certainly used in real world projects. By definition more projects use JPA than Spring Data JPA since the first is a superset of the later.
This involves complete Spring history,
Actual motive of Spring was to enable loose coupling , so that unit tests can be easily performed . Spring MVC was for developing web applications with Model View Controller having their proper boundaries.
Then Spring Boot which enabled developer to focus on business logic then configurations. That's why spring boot is a good choice for microservices.
For JPA or hibernate query , many people prefer using JPARepositoy as again you just have to define entity for the repository and Spring boot automatically provides you queries like findById and so on.
In short Spring boot have made it really easy to run the applications with different configurations and environment smoothly.

Is Spring Boot just for Microservices ? can i use Spring Boot for Monolithic architecture?

Is Spring Boot just for Microservices or can I use Spring Boot for Monolithic architecture?
Spring Boot in itself has nothing to do with microservices. It's a Spring module which simply makes the configuration of your app easier. As such, it absolutely can be used in a monolithic app.
From the official docs:
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
Features
Create stand-alone Spring applications
Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
Provide opinionated 'starter' dependencies to simplify your build configuration
Automatically configure Spring and 3rd party libraries whenever possible
Provide production-ready features such as metrics, health checks and externalized configuration
Absolutely no code generation and no requirement for XML configuration

Spring mvc and webflux in 1 spring boot application

I got below instruction from spring boot doc:
Adding both spring-boot-starter-web and spring-boot-starter-webflux modules in your application results in Spring Boot auto-configuring Spring MVC, not WebFlux. This behavior has been chosen because many Spring developers add spring-boot-starter-webflux to their Spring MVC application to use the reactive WebClient. You can still enforce your choice by setting the chosen application type to SpringApplication.setWebApplicationType(WebApplicationType.REACTIVE)
My question is:
What if my application contains both MVC services and webflux services?
Is it supported?
For example:
I may have some existing admin service which is MVC based. Now I want to add some new services with webflux style.
No, this is not supported. Spring MVC and Spring WebFlux have different runtime models and don't support the same servers (for example, Spring WebFlux can be run with Netty, Spring MVC cannot).
Also, Spring MVC and Spring WebFlux are full web frameworks, meaning each has its own infrastructure that somehow duplicates the other. Deploying both in the same app would make it difficult to map requests (which requests should go where?).

Spring contract-first REST

I have a Spring web application - which doesn't use Spring-based GUI, but Wicket - and I would like to build contract-first REST services.
I already have a contract defined in Swagger and I generate model and API artifacts. Swagger codegen generates either Spring Boot artifacts, or Spring MVC ones.
My intention is to use ideally just a model, and maybe API (controllers) from this generated code. But up to my knowledge/research, there is no simple way to have just simple REST service without MVC/Boot boilerplate.
Therefore my questions are:
Is it possible to build lightweight Spring-based REST service, without having "heavy" dependency of full Spring MVC/Spring Boot?
If not, which approach is more lightweight? Spring Boot, or Spring MVC?
You are misinterpreting the Spring ecosystem.
Spring MVC is THE rest web and web service library within Spring portfolio.
The same way as Spring-WS is THE soap web service library.
They are very similar in architecture and style of use.
The fact that Spring MVC is bundled with Spring Framework does not change the situation.
Spring Boot does not bring any new REST offering. It is just a bootstrap mechanism to start Java web server with web app already deployed from a plain main() method. Therefore if you see "Building REST web services with Spring Boot", it just means that it is Spring MVC bootstrapped by Spring Boot.
Therefore, the question to what is more lightweight is straightforward: Spring MVC.
To answer the question #2:
The usage of Spring MVC is more lighweight, then usage of Spring Boot:
Size of the WAR archive:
6,1 MB for Spring MVC
9,2 MB for Spring Boot
Number of libraries in WAR archive:
12 for Spring MVC
28 for Spring Boot

Resources