首页 文章

什么是'spring-boot-starter` jar ?

提问于
浏览
36

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

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

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

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

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

哪些Spring Boot jar 我真的需要在这些 jar 里使用这些功能?我的项目没有任何依赖管理 . 我的项目是使用Spring Security的Spring MVC应用程序 .

3 回答

  • 4

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

  • 21

    这些依赖项旨在为所有 needed dependencies 提供一个ad-hoc框架项目的统一条目 .

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

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

    参考, Spring Boot Starter POM .

    编辑:

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

    • 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-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

    可以在maven central repository中无缝地导航搜索结果 .

    请注意,这可能不是完整的参考列表,因为某些组件可能正在处理,因此工件可能会更新 .

  • 0

    您还可以使用以下命令来报告spring boot project pom.xml文件中定义的各种spring-boot-starter- *所需的依赖项 .

    mvn dependency:resolve
    

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

    注释格式为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
    

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

    如果您没有方便的 spring 启动项目,只需在Spring Initializr创建一个,使用您需要的任何 spring 启动启动器 . 它还使用maven wrapper,它包装了maven命令,节省了分别设置和安装maven的时间 .

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

    适用于Linux / Mac OS

    ./mvnw dependency:resolve
    

    对于窗户

    ./mvnw.cmd dependency:resolve
    

相关问题