SpringBoot --项目启动的两种方式
2.SpringBoot环境启动方法
2.1使用 maven 项目
- 引入依赖
<!-- 解决版本冲突关键 -->
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.5.3</version>
</parent><!-- 导入跟web开发相关的起步依赖 -->
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
</dependencies>
2.编写启动类
@SpringBootApplication
public class AppServer {public static void main(String[] args) {SpringApplication.run(AppServer.class, args);}
}
3.编写 Controller
//@Controller //表明当前是一个控制器,被 spring 容器管理
//@ResponseBody // 表明当前返回的是 json 格式
@RestController //是一个符合注解, 包含上面两个注解
public class HelloController {@GetMapping("/hello")public String hello() {return "hello spring boot";}
}
2.2使用 springInitializr
这个比较简单,不需要我们编写启动内和导入依赖,只需要按照步骤操做,便可自动实现