This week's book giveaway is in the Go forum.
We're giving away four copies of Head First Go and have Jay McGavren on-line!
See this thread for details.
Win a copy of Head First Go this week in the Go forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

SpringBoot vs Spring MVC  RSS feed

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey. I have got couple of questions about SpringBoot vs SpringMVC.

1) First question that comes to my mind is that, why SpringBoot has main class/method and SpringMVC does not?
2) SpringMVC needs war files, SpringBoot doesnt - it runs on jar files. Why is that? Both build web application.
3) According to https://spring.io/guides/gs/convert-jar-to-war/ -

A popular subject is that many people still wish to generate WAR files to be deployed inside containers.

, why people want to change jar files to war files? Is it not harder to debug and run application using war files?
 
Saloon Keeper
Posts: 9869
199
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

must Janik wrote:1) First question that comes to my mind is that, why SpringBoot has main class/method and SpringMVC does not?


Web applications run inside a web application container. Usually, this is a piece of software that is already running on a server somewhere. These containers provide a main method, so web applications loaded by them don't need a main method.

Spring Boot applications are not deployed in a web application container. Instead, the container is bundled together with the web application, so you can run it without requiring that a container is already installed on the host system. It needs a main method to start up the container that is bundled with the application.

2) SpringMVC needs war files, SpringBoot doesnt - it runs on jar files. Why is that? Both build web application.


Because one is deployed inside a pre-installed web application container, and they require WAR files. The other is a stand-alone application that can be run on its own, so it can be a regular old JAR file.

3) ... why people want to change jar files to war files? Is it not harder to debug and run application using war files?


Because most people don't want a huge JAR file that comes with a bundled web application container when they already have a container like Tomcat or Glassfish  installed on their system.
 
must Janik
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:
Web applications run inside a web application container. Usually, this is a piece of software that is already running on a server somewhere. These containers provide a main method, so web applications loaded by them don't need a main method.

Spring Boot applications are not deployed in a web application container. Instead, the container is bundled together with the web application, so you can run it without requiring that a container is already installed on the host system. It needs a main method to start up the container that is bundled with the application.



I do not understand it at all...
I need to press start to start up the container while deploying MVC app.
I need to press start to start up the container that is bundled with the application.

What is the difference? (I know that one has embedded container, the other not)
 
Stephan van Hulst
Saloon Keeper
Posts: 9869
199
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean "start" in your IDE?

When you press start for a Spring Boot app, your IDE starts the Java VM which in turn calls the main method.

When you press start for a normal web application, your IDE copies the WAR to a special folder of whatever web application container you have installed on your system, and starts the container service if it isn't already running. The container itself contains a main method, so the WAR doesn't need one.
 
must Janik
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Do you mean "start" in your IDE?

When you press start for a Spring Boot app, your IDE starts the Java VM which in turn calls the main method.



Why SpringBoot container that is bundled with it  does not have main method as SpringMVC then?
That it because I can change type of container?
 
must Janik
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean, why SpringBoot does not have the same solution as Spring MVC. Why not both has main method inside container or main method wrriten by ourselves.
 
Stephan van Hulst
Saloon Keeper
Posts: 9869
199
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container bundled in Spring Boot probably has a main method as well, just like a regular container. The Spring Boot application's main method calls the container's main method at some point.

Why does a normal WAR not have a main method? Because it's expected to be loaded by a service that's already running, nothing needs to be started.
 
must Janik
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two main methods? What is the sense of it. Why dont we have the same solution as at normal web app? No main method in our code, just in container?
 
Sheriff
Posts: 21653
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spring MVC can also run inside Spring Boot. The two are not mutually exclusive. Spring MVC needs a container to run in, but Spring Boot can provide that container. That's often an embedded Tomcat or Jetty container.
 
Rob Spoor
Sheriff
Posts: 21653
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

must Janik wrote:Two main methods? What is the sense of it. Why dont we have the same solution as at normal web app? No main method in our code, just in container?


Spring Boot provides the container. It's meant to be a fully standalone solution that replaces (sometimes heavyweight) containers. No more WebLogic, WebSphere, JBoss or anything else - just the embedded (Tomcat) container and the Spring and Spring Boot frameworks.
 
Stephan van Hulst
Saloon Keeper
Posts: 9869
199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

must Janik wrote:Why dont we have the same solution as at normal web app? No main method in our code, just in container?


Because the container is just a generic piece of software that doesn't know that it has to start your web application. When you start it up by its own main method, it still needs to be told what web application to run. That's what the outer wrapper main method does.
 
must Janik
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:

must Janik wrote:Why dont we have the same solution as at normal web app? No main method in our code, just in container?


Because the container is just a generic piece of software that doesn't know that it has to start your web application. When you start it up by its own main method, it still needs to be told what web application to run. That's what the outer wrapper main method does.



Okay, so comparing to Spring MVC what is the difference? I mean, I want to quote

When you start it up by its own main method, it still needs to be told what web application to run.

, Spring MVC does not needs to be tolds what web application to run?
 
Saloon Keeper
Posts: 20514
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Web applications are not "programs". They're actually more like DLLs in Windows. That is, they don't have a processing thread, so there's no "main program". The processing thread that runs a webapp is loaned to it for just long enough to process the webapp request and have it return a response, then the thread gets given back to the webapp server. Since a webapp is DLL-like, the web application server determines which of several servlets or JSPs to call to service an HTTP request and it does this by dissecting the URL request string into the parts that direct routing of the request.

Normally, the webapp server is a program - a Java Application. For example, a webapp can be deployed to Tomcat, Websphere, or any one of a host of other web application containers and Tomcat, WebSphere, and so forth are Java Applications. But there's a difference between deploying a web application in a web application container and running an actual stand-alone Application.

Spring Boot, however, creates what is basically a custom web application server (Application), complete with a pre-deployed web application inside it. So Spring Boot has a main class. But just to repeat one more time, web applications do not have a main class. Because, again, they are not "programs", they're collections of service routines.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!