SpringBoot官方文档翻译(七):增加类路径依赖

11.2 Adding Classpath Dependencies(增加类路径依赖)

1
2
3
4
5
6
Spring Boot provides a number of “Starters” that let you add     
jars to your classpath. Our sample application has already
used 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. It also provides a dependency-management 
section so that you can omit version tags for “blessed” dependencies.

Spring Boot 提供了一些“Starters”用于您增加一些jars包到您的类路径下。我们的示例应用已经使用了spring-boot-starter-parent在上一节的POM文件中。spring-boot-starter-parent是一个提供了非常有用的Maven默认的特殊的starter。它同样提供了一个dependency-management部分,以便于您可以为一些“幸福”依赖忽略版本标签。

1
2
3
4
5
Other “Starters” provide dependencies that you are likely to need     
when developing a specific type of application. Since we are
developing a web application, we add a spring-boot-starter-web 
dependency. Before that, we can look at what we currently have
by running the following command:

其他“Starters”提供了一些依赖,以便于您可以在开发一些特殊模式的应用,如果我们需要部署一个web应用,我们需要增加 spring-boot-starter-web的依赖。在此之前,我们可以使用以下命令寻找我们目前已有的依赖:

1
2
3
$ mvn dependency:tree

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

1
2
3
4
5
The mvn dependency:tree command prints a tree representation of     
your project dependencies. You can see that spring-boot-starter-parent 
provides no dependencies by itself. To add the necessary dependencies,
edit your pom.xml and add the spring-boot-starter-web dependency
immediately below the parent section:

mvn dependency:tree命令会将您的应用依赖以树形展示。您可以发现spring-boot-starter-parent本身并不提供任何依赖。如果需要增加必要的依赖,更改您的pom.xml,增加spring-boot-starter-web依赖紧接在父节点下面:

1
2
3
4
5
6
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

1
2
3
If you run mvn dependency:tree again, you see that there are now a     
number of additional dependencies, including the Tomcat web server
and Spring Boot itself.

如果您再次运行mvn dependency:tree,您将会看到一系列的新增的依赖,包括tomcat服务器和Spring Boot本身

分享到