HoneyMoose
  • 首页
  • Java
  • Jersey
  • Jira
  • Confluence
  • U.S.
    • USRealEstate
    • USVisaTrack
    • H1B
  • 项目和网站
    • CWIKI.US
    • OSSEZ 社区
    • WIKI.OSSEZ.COM
    • BUG.OSSEZ.COM
    • RSS.OSSEZ.COM
BLOG.OSSEZ.COM
A responsive blog theme focused om user reading experience
  1. Home
  2. Computer Science
  3. This article

Spring Boot 2.4 第一个示例程序添加 Classpath 依赖

2021年01月08日 463Browse 0Like 0Comments

Spring Boot 提供了一系列的 “Starters” 来让你将 Jar 添加到你的 classpath 路径中。 我们的项目提供了一系列的 smoke tests,需要使用 spring-boot-starter-parent 定义在 POM 文件的 parent 部分。如果你对 smoke tests 不太了解的话,请参考相关定义和搜索相关文档。 在这里 smoke tests 的定义就是能够让项目能够跑起来,并且实现一些基本的功能。

spring-boot-starter-parent 是一个特殊的 starter。在这个定义中,我们为 Maven 提供了一些有用的默认配置。 同时 spring-boot-starter-parent 还提供了一些 [dependency-management]。 因为上面的的配置,针对依赖,你可以针对 “blessed” 忽略掉 version 标签。

当你针对 Spring Boot 在应用中,想使用一些特定的功能或者构建一些特定的应用,你可以针对需要来选择其他的 “Starters”。 针对当前的示例,我们打算是构建一个 Web 应用程序,因此我们需要添加一个 spring-boot-starter-web 到依赖(dependency)中。 在进行上面的操作之前,我们可以通过运行下面的命令来查看我们当前项目中使用的依赖:

$ mvn dependency:tree

[INFO] com.example:myproject:jar:0.0.1-SNAPSHOT

 

spring-boot-tree-01

 

mvn dependency:tree 命令行将会针对你的项目使用的依赖打印出依赖的树结构。 现在,你可以看到 spring-boot-starter-parent,但是还没有添加其他的依赖。 如果想添加一些必要的依赖,编辑你的 pom.xml 然后添加 spring-boot-starter-web 依赖代码到 pom.xml 文件的 parent 部分后面。 具体的代码内容,请参考下面的示例:

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

当你再次运行 mvn dependency:tree 的时候,你可以看到在你当前的项目中已经添加上去一些其他的依赖了。包括有 Tomcat web server 和 Spring Boot 本身。

 

spring-boot-tree-02

 

上图显示的是添加 Web 依赖后显示的树。我们会发现添加的 jar 已经明显多了很多。

使用 Maven 的好处是,你不再需要指定版本,可以通过 Maven 直接进行管理。

https://www.ossez.com/t/spring-boot-2-4-classpath/1098

Tags: None
Last updated:2021年01月08日

Kratos

stay absorbed stay excellent

Like
< Previous
Next >

Comments

Cancel reply

Newest Hotspots Random
Newest Hotspots Random
IntelliJ IDEA 2023.1 版本添加了包中类的列表功能 Jenkins 修改启动的端口 Spring 项目运行提示错误 Not a managed type Linux 查看 SELinux 的状态 WordPress 网站 Error Establishing a Database Connection(建立数据库连接时出错) Linux 开启或关闭 SELinux
Hibernate 5 @Entity 如何 extends 另外一个类 在虚拟环境下运行 Confluence 6 Confluence 6 示例 - https://confluence.atlassian.com/ ISO-8601 如何解读 Confluence 6 大致的用户规模示例 Confluence 6 添加或删除用户组
Categories
  • Algorithm(算法)
  • AMQP
  • Angular
  • CI
  • Compile And CI
  • Computer Science
  • Confluence
  • DataBase
  • Gradle
  • H1B
  • Hibernate
  • IDE
  • Java
  • Jersey
  • Jira
  • MariaDB
  • PrestaShop
  • Spring
  • Spring Batch
  • U.S.
  • USRealEstate
  • USVisaTrack
  • 我的小厨

COPYRIGHT © 2020 HoneyMoose. ALL RIGHTS RESERVED.

THEME CWIKIUS.CN MADE BY VTROIS