11.2 添加 Classpath 依賴

2018-08-14 15:06 更新

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. SpringBoot提供一許多“Starter”,讓您添加jar包到類路徑(classpath)中。 我們例子應(yīng)用程序在POM文件的parent節(jié)點(diǎn)中使用(繼承)了spring-boot-starter-parent。 spring-boot-starter-parent是一個(gè)特殊的“starter”, 提供了有用的Maven默認(rèn)值。 同時(shí)提供了dependency-management,因此您可以省略“blessed”依賴包的SpringBoot提供一許多“Starter”,讓您添加jar包到類路徑(classpath)中。 我們例子應(yīng)用程序中Pom文件(繼承的)父POM文件中使用了spring-boot-starter-parentspring-boot-starter-parent是一個(gè)特殊的“starter”, 提供了有用的Maven默認(rèn)值。 同時(shí)還提供了dependency-management節(jié)點(diǎn),因此您可以(在引用依賴 包時(shí))省略“blessed”依賴的標(biāo)簽。

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: 其他“Starter”提供了您可能在開(kāi)發(fā)一個(gè)特定類型的應(yīng)用程序時(shí)需要的依賴。 由于我們要開(kāi)發(fā)一個(gè)Web應(yīng)用程序,因此我們添加了spring-boot-starter-web依賴。 在此之前, 我們能看一下當(dāng)前有的依賴,通過(guò)運(yùn)行以下命令:

$ mvn dependency:tree


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

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命令打印了您的以樹(shù)形表現(xiàn)的項(xiàng)目依賴。您能夠看見(jiàn)spring-boot-starter-parent本身沒(méi)有提供依賴。為添加必需的依賴, 編輯pom.xml,添加mvn dependency:tree命令打印了您的以樹(shù)形表現(xiàn)的項(xiàng)目依賴。您能夠看見(jiàn)spring-boot-starter-parent本身沒(méi)有提供依賴。為添加必需的依賴, 編輯pom.xml,在緊接著parent節(jié)點(diǎn)后面添加spring-boot-starter-web依賴:

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

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.

如果您再次運(yùn)行mvn dependency:tree, 您會(huì)看到現(xiàn)在有許多額外的依賴項(xiàng), 包括Tomcat Web服務(wù)器和SpringBoot本身。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)