0
votes

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:

  1. Is it possible to build lightweight Spring-based REST service, without having "heavy" dependency of full Spring MVC/Spring Boot?

  2. If not, which approach is more lightweight? Spring Boot, or Spring MVC?

2
This is a question of opinion, and is therefore off-topic on StackOverflow. That said, it's super easy to create a RESTful webservice with Spring Boot.Jesper
You are right, I'm going to re-formulate the question. I would rather avoid to use Spring Boot.Vít Kotačka
When you use Spring Boot, you are also using Spring Web MVC - in my opinion there's not a lot of difference between using Spring Boot or a plain old Spring webapp, you're not gaining a lot by not using Spring Boot. Also, why do you think this is "heavyweight"?Jesper
By heavyweight, I mean the difference between a lean application and boilerplate libraries, or transitive dependencies which I don't need for any functionality, but still packed in the application. E.g. difference between MVC and Boot is: 12 vs. 28 libraries and 6 vs. 9 MB of WAR archive.Vít Kotačka
@VítKotačka maybe look into JLink for the packaging? I believe it should cut down on unused modules and create a custom JRE just for you.payne

2 Answers

2
votes

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.

0
votes

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