最近项目一直用的都是SpringBoot,顺便总结一下SpringBoot的各种配置,想最简洁的运行一个SpringBoot程序,需要下面步骤
- 构建一个maven项目,项目目录结构如下
- 配置pom
<?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.blog.springboot</groupId> <artifactId>springboot</artifactId> <version>1.0-SNAPSHOT</version> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>1.3.1.RELEASE</version> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>1.3.1.RELEASE</version> </dependency> </dependencies> </project>
- 创建启动类
@SpringBootApplication @RestController public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @RequestMapping("/") public String hello() { return "hello world"; } }
- 执行启动类中的main方法
- 浏览器输入localhost:8080
到这里,我们第一个spring程序就启动了
时间: 2024-11-05 10:28:33