IDEA SpringBoot多模块
parent:管理版本
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
子模块
<parent>
<artifactId>SpringBoot02-Parent</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>SpringBoot02-Config</artifactId>
<dependencies>
<!-- 导入相关的场景启动器,就会把相关的依赖一起导入进来-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--导入配置文件处理器,配置文件进行绑定就会有提示-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
打包运行
<parent>
<artifactId>SpringBoot02-Parent</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>SpringBoot02-Config</artifactId>
<dependencies>
<!-- 导入相关的场景启动器,就会把相关的依赖一起导入进来-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--导入配置文件处理器,配置文件进行绑定就会有提示-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
入门探究
pom.xml 非多模块化项目
一
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
</parent>
父亲模块spring-boot-dependencies,版本仲裁中心
二 导入场景启动器
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
三 打包
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
@SpringBootApplication
-
是一个配置类
-
导入当前类所在包及子子孙孙包加了注解的类
加入一大堆配置类
配置类被加载后会进行自动配置,让我们在使用时无需做配置
SpringBoot配置
配置文件
yml
多环境支持
- 定义多套环境
- 启用默认环境
- 开发时切换环境
- 打包切换环境
SpringBoot测试
@RunWith(SpringRunner.class)
@SpringBootTest(classes = App.class)