Spring contract-first REST - spring

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

Related

Spring Boot Confusion (using spring cloud dependency in spring boot framework)

I am new to spring framework. I have a confusion regarding spring boot and spring cloud.
I used https://start.spring.io/ to initialize a spring boot application. I think I am using the spring boot framework. However, I would like to use some spring cloud dependencies such as spring-cloud-stream-binder-kafka.
Question 1: If I added this dependency above to my spring boot application, I am wondering if I still can go with the spring boot framework, or I have to change to spring cloud framework.
Question 2: I am wondering if there is any difference when deploying the spring boot or spring cloud application. Or, they just have the different frameworks, and we could deploy them in the same way.
Thank you so much!
You can use together Spring Boot and Spring Cloud packages.
Spring Boot is just a preconfigured Spring Framework with some extra functionalities. It also uses library versions compatibile with each other. Spring Cloud is also the part of the Spring ecosystem, contains libraries that mostly used in cloud applications.
In the background, these packages will pull all necessary Spring (and other) libraries into your project, as transitive dependencies.
So you can use the generated pom/gradle, and add other dependencies. In this case Spring boot will be your core and cloud add extras.

Spring Boot and Spring MVC are actually frameworks or not?

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

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 boot for legacy Struts application

I have come across couple of discussions here about Spring Boot setup for Struts application but did not get a valid yes or no.
I know we can migrate the struts to spring and then use it with Spring boot but considering the timelines and application complexity we need to just migrate from Legacy Websphere to Spring boot for the Struts application.
Can we integrate spring boot with a legacy Struts 1.x application ?
P.S:
So far I am able to start up tomcat for spring boot successfully for my war but I do get 404 on browser so need to understand what would be the flow after the request flow to Main class.

Resources