ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
### 10.1.1. Maven安装 Spring Boot兼容Apache Maven 3.2或更高版本。如果本地没有安装Maven,你可以参考[maven.apache.org](http://maven.apache.org/)上的指南。 **注**:在很多操作系统上,可以通过包管理器来安装Maven。OSX Homebrew用户可以尝试`brew install maven`,Ubuntu用户可以运行`sudo apt-get install maven`。 Spring Boot依赖使用的groupId为`org.springframework.boot`。通常,你的Maven POM文件会继承`spring-boot-starter-parent`工程,并声明一个或多个[“Starter POMs”](../III. Using Spring Boot/13.4. Starter POMs.md)依赖。此外,Spring Boot提供了一个可选的[Maven插件](../VIII. Build tool plugins/58. Spring Boot Maven plugin.md),用于创建可执行jars。 下面是一个典型的pom.xml文件: ```xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>myproject</artifactId> <version>0.0.1-SNAPSHOT</version> <!-- Inherit defaults from Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.BUILD-SNAPSHOT</version> </parent> <!-- Add typical dependencies for a web application --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <!-- Package as an executable jar --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <!-- Add Spring repositories --> <!-- (you don't need this if you are using a .RELEASE version) --> <repositories> <repository> <id>spring-snapshots</id> <url>http://repo.spring.io/snapshot</url> <snapshots><enabled>true</enabled></snapshots> </repository> <repository> <id>spring-milestones</id> <url>http://repo.spring.io/milestone</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <url>http://repo.spring.io/snapshot</url> </pluginRepository> <pluginRepository> <id>spring-milestones</id> <url>http://repo.spring.io/milestone</url> </pluginRepository> </pluginRepositories> </project> ``` **注**:`spring-boot-starter-parent`是使用Spring Boot的一种不错的方式,但它并不总是最合适的。有时你可能需要继承一个不同的父 POM,或只是不喜欢我们的默认配置,那你可以使用import作用域这种替代方案,具体查看[Section 13.2.2, “Using Spring Boot without the parent POM”](../III. Using Spring Boot/13.1.2. Using Spring Boot without the parent POM.md)。