What are `spring-boot-starter` jars?

JavaSpringMavenSpring Boot

Java Problem Overview


In Spring Boot, there are some jars on the pattern of spring-boot-starter. All these jars do not contain any packages. What is their use?

In Maven POMs, the following dependencies are added:

  • org.springframework.boot:spring-boot-starter-web
  • org.springframework.boot:spring-boot-starter-actuator
  • org.springframework.boot:spring-boot-starter-security

Which Spring Boot jars do I actually need to use the functionality in these jars? My project does not have any dependency management. My project is a Spring MVC application which uses Spring Security.

Java Solutions


Solution 1 - Java

Those dependencies are meant to provide a unified entry to an ad-hoc skeleton project with all needed dependencies.

They should usually be inherited from your project descriptor (pom.xml) so that you get all parent dependecies with configured versions. No more burden to be done on the developer side:

> Starter POMs are a set of convenient dependency descriptors that you can include in your application. You get a one-stop-shop for all the Spring and related technology that you need, without having to hunt through sample code and copy paste loads of dependency descriptors. For example, if you want to get started using Spring and JPA for database access, just include the spring-boot-starter-data-jpa dependency in your project, and you are good to go.

Reference, Spring Boot Starter POM.

Edit:

Those POMs can be used to synthesize the dependencies that can be used for a certain kind of project, e.g. for a simple Spring MVC project, the following artifacts are to be included (Read from spring-boot-starter, spring-boot-starter-web, spring-boot-starter-security respectively):

  • Spring Boot artifacts:
    • org.springframework.boot:spring-boot
    • org.springframework.boot:spring-boot-autoconfigure
    • org.springframework.boot:spring-boot-starter-logging
  • Spring Core, Web, MVC, Security artifacts:
    • org.springframework:spring-core
    • org.springframework:spring-web
    • org.springframework:spring-webmvc
    • org.springframework:spring-beans
    • org.springframework:spring-context
    • org.springframework:spring-expression
    • org.springframework:spring-aop
    • org.springframework.security:spring-security-config
    • org.springframework.security:spring-security-web
    • org.hibernate:hibernate-validator
    • com.fasterxml.jackson.core:jackson-databind

The artifacts can be found seamlessly navigating search results in the maven central repository.

Note that this may not be a full fledged reference list as some components may be mising thus the artifacts are subject to be updated.

Solution 2 - Java

Simply stated they are dependency descriptors that list transitive dependencies with versions that are tested to work together to save you time from trying to put libraries together that take care of some facet of an application.

Solution 3 - Java

You can also get maven to report the dependencies required by the various spring-boot-starter-* defined in spring boot project pom.xml file, by using the following command

mvn dependency:resolve

For example with spring 1.5.8.RELEASE, the following jars (and versions) are used

Note format is Group Id:Artifact Id:Version:Scope

The following files have been resolved:
    com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
    org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
    aopalliance:aopalliance:jar:1.0:compile
    org.hamcrest:hamcrest-library:jar:1.3:test
    org.mockito:mockito-core:jar:1.10.19:test
    org.assertj:assertj-core:jar:2.6.0:test
    org.springframework:spring-beans:jar:4.3.12.RELEASE:compile
    org.springframework.boot:spring-boot-test:jar:1.5.8.RELEASE:test
    org.springframework.boot:spring-boot-autoconfigure:jar:1.5.8.RELEASE:compile
    org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.8.RELEASE:compile
    org.skyscreamer:jsonassert:jar:1.4.0:test
    org.yaml:snakeyaml:jar:1.17:runtime
    com.fasterxml:classmate:jar:1.3.4:compile
    org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
    org.springframework.boot:spring-boot-starter-test:jar:1.5.8.RELEASE:test
    org.hamcrest:hamcrest-core:jar:1.3:test
    com.jayway.jsonpath:json-path:jar:2.2.0:test
    org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.23:compile
    org.springframework.boot:spring-boot:jar:1.5.8.RELEASE:compile
    org.apache.tomcat:tomcat-annotations-api:jar:8.5.23:compile
    org.springframework:spring-context:jar:4.3.12.RELEASE:compile
    org.hibernate:hibernate-validator:jar:5.3.5.Final:compile
    javax.validation:validation-api:jar:1.1.0.Final:compile
    org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.23:compile
    org.springframework.boot:spring-boot-starter-logging:jar:1.5.8.RELEASE:compile
    com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
    org.ow2.asm:asm:jar:5.0.3:test
    org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.23:compile
    org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
    org.springframework:spring-web:jar:4.3.12.RELEASE:compile
    ch.qos.logback:logback-core:jar:1.1.11:compile
    org.springframework.security:spring-security-core:jar:4.2.3.RELEASE:compile
    org.springframework:spring-test:jar:4.3.12.RELEASE:test
    org.springframework.boot:spring-boot-starter:jar:1.5.8.RELEASE:compile
    org.springframework.security:spring-security-test:jar:4.2.3.RELEASE:test
    org.springframework.boot:spring-boot-starter-web:jar:1.5.8.RELEASE:compile
    org.springframework:spring-core:jar:4.3.12.RELEASE:compile
    org.springframework.boot:spring-boot-starter-security:jar:1.5.8.RELEASE:compile
    org.springframework.boot:spring-boot-actuator:jar:1.5.8.RELEASE:compile
    org.objenesis:objenesis:jar:2.1:test
    org.springframework:spring-expression:jar:4.3.12.RELEASE:compile
    org.springframework.boot:spring-boot-starter-actuator:jar:1.5.8.RELEASE:compile
    org.springframework.security:spring-security-config:jar:4.2.3.RELEASE:compile
    org.springframework.security:spring-security-web:jar:4.2.3.RELEASE:compile
    org.springframework:spring-aop:jar:4.3.12.RELEASE:compile
    junit:junit:jar:4.12:test
    org.slf4j:slf4j-api:jar:1.7.25:compile
    net.minidev:json-smart:jar:2.2.1:test
    org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.8.RELEASE:test
    net.minidev:accessors-smart:jar:1.1:test
    org.springframework:spring-webmvc:jar:4.3.12.RELEASE:compile
    ch.qos.logback:logback-classic:jar:1.1.11:compile
    org.slf4j:jul-to-slf4j:jar:1.7.25:compile
    com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile

Just ignore the jars that have a test scope for deployment.

If you do not have spring boot project handy, just create one at [Spring Initializr][1], with whatever spring boot starters you need. It also uses [maven wrapper][2], which wraps the maven command, saving you time setting up and installing maven separately.

So just download the zip file from Spring Initializr, unzip and open a command prompt in the unzipped folder, and use the following command instead

For Linux/Mac OS

 ./mvnw dependency:resolve
 

For windows

 ./mvnw.cmd dependency:resolve

 

[1]: http://start.spring.io "Spring Initializr" [2]: https://github.com/takari/maven-wrapper

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkhateebView Question on Stackoverflow
Solution 1 - JavatmarwenView Answer on Stackoverflow
Solution 2 - JavaAlexander SuraphelView Answer on Stackoverflow
Solution 3 - JavaSanjView Answer on Stackoverflow