如何启动springboot
时间: 2023-09-11 14:11:59 浏览: 42
启动 Spring Boot 有多种方式,其中最常见的方式是通过 Maven 插件或者 Gradle 插件启动。以下是使用 Maven 插件启动 Spring Boot 的方式:
1. 在 pom.xml 文件中添加 Spring Boot Starter Parent 依赖:
```xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
```
2. 添加 Spring Boot Starter Web 依赖:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
```
3. 在 pom.xml 文件中添加 Maven 插件:
```xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
```
4. 在命令行窗口中进入项目根目录,执行以下命令:
```bash
mvn spring-boot:run
```
5. Spring Boot 应用程序将会启动并监听默认端口(8080),使用浏览器访问 http://localhost:8080 即可访问应用程序。
注意:上述步骤假设你已经安装了 Maven,并且已经配置了环境变量。如果你使用的是 Gradle,可以参考 Spring Boot 官方文档中关于 Gradle 的配置方式。