1)项目中只须要依赖父工程spring-boot-starter-parent便可,该父工程中管理了不少springboot须要的依赖包及其版本。web
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> <relativePath/> </parent>
relativePath的做用:spring
默认值为../pom.xml, 查找依赖父项目的顺序为: relativePath元素中的地址 - 本地仓库 - 远程仓库tomcat
<relativePath/> 就是配置了一个空的元素,意思是:始终从仓库中获取,不从本地路径获取。springboot
2)添加spring-boot-starter-parent父工程后,项目若是须要使用springmvc和spring的jar包,只须要添加以下依赖:mvc
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
不须要添加版本,由于版本号在父工程中统一管理了app
3)写第一个入门程序spring-boot
//开启Springboot的默认自动配置 @EnableAutoConfiguration @Controller public class IndexController { @RequestMapping("/") @ResponseBody public String first() { return "Hello World!"; } public static void main(String[] args) { /** * springboot的启动方法 * 第一个参数:当前文件的字节码 * 第二个参数:main方法的参数 */ SpringApplication.run(IndexController.class, args); } }
main方法启动便可,内嵌tomcat运行,端口号默认为8080,启动后页面输入localhost:8080/便可访问spa
若是想关闭某个第三方类自动配置,能够这样排除:@EnableAutoConfiguration(exclude = {RedisAutoConfiguration.class})code
4)springboot的全局配置文件xml
名称必须为application.properties 或者是 application.yml,放在resources目录下或者类路径下的/config下,通常咱们放在resources下;