Spring Boot项目的探究
一、pom.xml文件
1.父项目
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
父项目打开后:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.2.2.RELEASE</version> <relativePath>../../spring-boot-dependencies</relativePath> </parent>
这是用来管理Spring Boot应用中所有的依赖版本,以后导入这些依赖默认不需要指定版本,没有在dependencies中管理的依赖需要声明版本;
2.导入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
spring-boot-starter:spring-boot场景启动器;
spring-boot-starter-web:spring-boot中的web场景启动器,用于导入web模块正常运行依赖的组件。
Spring Boot将所有的功能场景都抽取出来,做成一个个的starter (启动器) , 只需要在项目里面引入需要场景的启动器,对应所需的依赖都会自动导入,版本也会自动控制。
二、主程序类
1.@SpringBootApplication注解
用于标注Spring Boot项目的主配置类,项目的启动通过执行该类中的main()方法,这是一个组合注解,主要组成如下:
@SpringBootConfiguration:Spring Boot配置类;
@EnableAutoConfiguration:开启自动配置功能,如注解扫描等;
三、resources文件夹
文件夹结构:static、templates、application.properties
1.static:保存所有静态资源,如js、css、图片等
2.templates:保存所有模板页面
3.application.properties:Spring Boot应用的配置文件,用于修改默认配置,如修改服务器端口号 server.port=8081
Spring Boot文件默认有两种全局配置文件application.properties或application.yml
配置文件作用:修改Spring Boot自动配置的默认值