Java 什么是“spring-boot-starter”罐子?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28273543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 05:54:17  来源:igfitidea点击:

What are `spring-boot-starter` jars?

javaspringmavenspring-boot

提问by khateeb

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?

在 Spring Boot 中,spring-boot-starter. 所有这些 jar 都不包含任何包。它们的用途是什么?

In Maven POMs, the following dependencies are added:

在 Maven POM 中,添加了以下依赖项:

  • org.springframework.boot:spring-boot-starter-web
  • org.springframework.boot:spring-boot-starter-actuator
  • org.springframework.boot:spring-boot-starter-security
  • 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.

我实际上需要使用哪些 Spring Boot jar 来使用这些 jar 中的功能?我的项目没有任何依赖管理。我的项目是一个使用 Spring Security 的 Spring MVC 应用程序。

采纳答案by tmarwen

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:

它们通常应该从您的项目描述符 ( pom.xml)继承,以便您获得具有配置版本的所有父依赖项。开发者方面不再有负担:

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.

Starter POM 是一组方便的依赖项描述符,您可以将其包含在您的应用程序中。您可以获得所需的所有 Spring 和相关技术的一站式服务,而无需搜索示例代码和复制粘贴加载的依赖项描述符。例如,如果您想开始使用 Spring 和 JPA 进行数据库访问,只需在您的项目中包含 spring-boot-starter-data-jpa 依赖项,就可以了。

Reference, Spring Boot Starter POM.

参考,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-securityrespectively):

这些 POM 可用于合成可用于某种项目的依赖项,例如对于一个简单的 Spring MVC 项目,将包含以下工件(从spring-boot-starter 中读取,spring-boot-starter- webspring-boot-starter-security分别):

  • 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.Hymanson.core:Hymanson-databind
  • Spring Boot 工件:
    • org.springframework.boot:spring-boot
    • org.springframework.boot:spring-boot-autoconfigure
    • org.springframework.boot:spring-boot-starter-logging
  • Spring Core、Web、MVC、安全工件:
    • org.springframework:spring-core
    • org.springframework:spring-web
    • org.springframework:spring-webmvc
    • org.springframework:spring-beans
    • org.springframework:spring-context
    • org.springframework:spring-表达式
    • org.springframework:spring-aop
    • org.springframework.security:spring-security-config
    • org.springframework.security:spring-security-web
    • org.hibernate:hibernate-validator
    • com.fasterxml.Hymanson.core:Hymanson-databind

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

可以在Maven 中央存储库中无缝导航搜索结果中找到这些工件。

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.

请注意,这可能不是一个完整的参考列表,因为某些组件可能会丢失,因此工件可能会更新。

回答by Alexander Suraphel

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.

简单地说,它们是依赖项描述符,列出了经过测试可以协同工作的版本的传递依赖项,以节省您尝试将处理应用程序某些方面的库放在一起的时间。

回答by Sanj

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

也可以让maven上报spring boot项目pom.xml文件中定义的各种spring-boot-starter-*所需要的依赖,使用如下命令

mvn dependency:resolve

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

例如对于 spring 1.5.8.RELEASE,使用以下 jars(和版本)

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

注释格式为 Group Id:Artifact Id:Version:Scope

The following files have been resolved:
    com.fasterxml.Hymanson.core:Hymanson-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.Hymanson.core:Hymanson-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.Hymanson.core:Hymanson-databind:jar:2.8.10:compile

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

只需忽略具有部署测试范围的 jar。

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.

如果您手边没有 spring boot 项目,只需在Spring Initializr 中创建一个,使用您需要的任何 spring boot starters。它还使用了maven wrapper,它包装了 maven 命令,从而节省了单独设置和安装 maven 的时间。

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

所以只需从 Spring Initializr 下载 zip 文件,解压并在解压后的文件夹中打开命令提示符,然后使用以下命令代替

For Linux/Mac OS

对于 Linux/Mac 操作系统

 ./mvnw dependency:resolve

For windows

窗户用

 ./mvnw.cmd dependency:resolve