Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are `spring-boot-starter` jars?

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.

like image 562
khateeb Avatar asked Feb 02 '15 08:02

khateeb


People also ask

What is spring boot starter jars?

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.

What is the starter that can be used to add spring boot dependency jars?

Adding Classpath Dependencies. Spring Boot provides a number of “Starters” that let you add jars to your classpath. Our applications for smoke tests use the spring-boot-starter-parent in the parent section of the POM. The spring-boot-starter-parent is a special starter that provides useful Maven defaults.

Should you use spring boot starter?

However, if you want to use any features related to Spring Boot, then i would advise you to use the starters, since they include all required dependencies and enable the necessary auto configuration classes.

What is included in spring-boot-starter-web?

The spring-boot-starter-web contains the spring web dependencies that includes spring-boot-starter-tomcat. The spring-boot-starter-web contains the following: spring-boot-starter. jackson.


3 Answers

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.

like image 187
tmarwen Avatar answered Oct 18 '22 01:10

tmarwen


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.

like image 32
Alexander Suraphel Avatar answered Oct 18 '22 00:10

Alexander Suraphel


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, with whatever spring boot starters you need. It also uses maven wrapper, 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
like image 1
Sanj Avatar answered Oct 18 '22 01:10

Sanj