首先使用idea新建一个maven项目,然后在pom.xml添加如下依赖
<!--引入spring boot并设置版本-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<!--开发web相关-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--springboot单元测试-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
然后编写启动类
/**
*
* @Author shiJb
* @create 2020/10/29 10:09
* @SpringBootApplication 开启了Spring的组件扫描和springboot的自动配置功能,相当于将以下三个注解组合在了一起
* @Configuration 表名该类使用基于Java的配置,将此类作为配置类。
* @ComponentScan 启用注解扫描。
* @EnableAutoConfiguration 开启springboot的自动配置功能。
*/
@SpringBootApplication
public class SjbController {
public static void main(String[] args) throws Exception {
SpringApplication.run(SjbController.class, args);
}
}
这样一个最基础的spring boot项目已经搭建好了,接下来我们编写一个欢迎页
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "<h1>Welcome to the world of shijinbo<h1>";
}
}
然后我们启动刚才编写好的启动类来访问我们刚编写的欢迎页
至此,我们就搭建完成了一个最基础的spring boot项目