Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring initializr: spring-boot-starter vs spring-boot-starter-web

I am trying to develop a sample spring boot based application in IntellIJ. So I used spring Initialzr approach, and made default selections during the setup. The pom.xml I ended up with has following dependency:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
</dependency>

But the tutorial I am following has following:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
</dependency>

So, what's the difference? And can I have both?

like image 510
Mandroid Avatar asked Jan 31 '19 05:01

Mandroid


3 Answers

spring-boot-starter-web contains the following dependencies:

  • spring-boot-starter
  • jackson
  • spring-core
  • spring-mvc
  • spring-boot-starter-tomcat

Using IntelliJ, you can view the dependencies of your artifacts at the bottom of the project structure.

Given that spring-boot-starter is a dependency of spring-boot-starter-web, it would be useless to have both. It wouldn't do any harm if you kept both either, just unnecessary.

like image 64
Brandon Avatar answered Oct 11 '22 14:10

Brandon


spring-boot-starter provides the basic development and run time infrastructure for your application along with core spring features. If you want web capabilities such as spring-mvc to your project you need to use spring-boot-starter-web. However if you use spring-boot-starter-web you do not need to to explicitly mention spring-boot-starter.

like image 21
keth Avatar answered Oct 11 '22 14:10

keth


spring-boot-starter is itself a dependency of spring-boot-starter-web. If you include only spring-boot-starter dependency into your application then you will get only runtime infrastructure along with some core features. So for the web application you need to include spring-boot-starter-web so that you can get spring-mvc, jackson and spring-boot-starter. There is no need of using both. If you will use spring-boot-starter-web then it will be enough for your application. However using both will not will not through an error.

like image 3
salman94 Avatar answered Oct 11 '22 15:10

salman94