English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
spring-boot-starter-parent是项目启动器。它为我们的应用程序提供了默认配置。所有依赖项都在内部使用它。所有的Spring Boot项目在pom.xml文件中都将spring-boot-starter-parent用作父项。
<parent></ <groupId>org.springframework.boot</<groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>14.0.RELEASE</version> </parent>
Parent Poms使我们可以管理多个子项目和模块的以下内容:
Configuration: 它使我们能够维护Java版本和其他相关属性的一致性。 Dependency Management: 它控制依赖性的版本以避免冲突。 源编码 默认Java版本 资源过滤 它还控制默认的插件配置。
spring-boot-starter-parent从spring-boot-dependencies继承依赖关系管理。我们只需要指定Spring Boot版本号即可。如果需要额外的启动器,我们可以安全地省略版本号。
Spring Boot Starter Parent定义了spring-boot。 -依赖关系作为父pom。它从spring-boot-dependencies继承了依赖管理。
<parent></ <groupId>org.springframework.boot</<groupId> <artifactId>spring-boot-dependencies</artifactId> <version>16.0.RELEASE</version> <relativePath>..<//../spring-boot-dependencies</relativePath> </parent>
默认父Pom
<properties> <java.version></18</java.version> <resource.delimiter>@<<//resource.delimiter> <project.build.sourceEncoding>UTF</-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF</-8</project.reporting.outputEncoding> <maven.compiler.source>${java.version}<//maven.compiler.source> <maven.compiler.target>${java.version}<//maven.compiler.target> </Eigenschaften>
属性部分定义应用程序默认值。Java的默认版本是18。我们还可以通过在项目pom中指定属性
Plugin-Verwaltung
spring -boot-starter-parent bestimmt viele Standardkonfigurationen für Plugins, einschließlich maven-failsafe-plugin, maven-jar-plugin und maven-surefire-plugin.
<plugin> <groupId>org.apache.maven.plugins</<groupId> <artifactId>maven-failsafe-plugin</artifactId> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</<groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>${start-class}</mainClass> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</<groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <includes> <include>**/*Tests.java</include> <include>**/*Test.java</include> </includes> <excludes> <exclude>**/Abstract*.java</exclude> </excludes> </configuration> </plugin>
Spring Boot-Abhängigkeiten
spring-boot-starter-parent-Abhängigkeit von spring-Die Abhängigkeiten von Spring Boot werden von den boot-Abhängigkeiten geerbt und haben alle diese Eigenschaften. Daher verwaltet Spring Boot die Abhängigkeitsliste als Teil der Abhängigkeitsverwaltung.
<properties> <activemq.version>5134</activemq.version> ... <ehcache.version>2102221</ehcache.version> <ehcache3.version>311</ehcache3.version> ... <h2.version>14192</h2.version> <hamcrest.version>13</hamcrest.version> <hazelcast.version>364</hazelcast.version> <hibernate.version>5.0.9.Final</hibernate.version> <hibernate-validator.version>524.Final</hibernate-validator.version> <hikaricp.version>247</hikaricp.version> <hikaricp-java6.version>2313</hikaricp-java6.version> <hornetq.version>247.Final</hornetq.version> <hsqldb.version>233</hsqldb.version> <htmlunit.version>221</htmlunit.version> <httpasyncclient.version>412</httpasyncclient.version> <httpclient.version>452</httpclient.version> <httpcore.version>445</httpcore.version> <infinispan.version>822.Final</infinispan.version> <jackson.version>281</jackson.version> .... <jersey.version>2231</jersey.version> <jest.version>2.0.3</jest.version> <jetty.version>9311.v20160721</jetty.version> <jetty-jsp.version>22.0.v201112011158</jetty-jsp.version> <spring-security.version>411/spring-security.version> <tomcat.version>854</tomcat.version> <undertow.version>1323.Final</undertow.version> <velocity.version>17</velocity.version> <velocity-tools.version>2.0</velocity-tools.version> <webjars-hal-browser.version>9f96c74</webjars-hal-browser.version> <webjars-locator.version>0.32</webjars-locator.version> <wsdl4j.version>163</wsdl4j.version> <xml-apis.version>14.01</xml-apis.version> </Eigenschaften> <Voraussetzungen> <maven>321</maven> </Voraussetzungen>
In einigen Fällen benötigen wir nicht die Vererbung von pom.xml-Datei in spring-boot-starter-parent. Um solche Fälle zu behandeln, bietet Spring Boot Flexibilität, indem er nicht von spring-boot-starter-Im Fall von parent wird weiterhin Abhängigkeitsverwaltung verwendet.
<dependencyManagement> <dependencies> <dependency> <!-- Importiere Abhängigkeitsverwaltung von Spring Boot --> <groupId>org.springframework.boot</<groupId> <artifactId>spring-boot-dependencies</artifactId> <version>211/version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Im obigen Code können wir sehen, dass wir dies verwendet haben <Scope>Tag. Wenn wir verschiedene Versionen für bestimmte Abhängigkeiten verwenden möchten, ist dies sehr nützlich.