2020-02-06 Spring Boot02

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

  • 是一个配置类


    image.png

    image.png
  • 导入当前类所在包及子子孙孙包加了注解的类


    image.png
  • 加入一大堆配置类

  • 配置类被加载后会进行自动配置,让我们在使用时无需做配置

SpringBoot配置

配置文件

yml

多环境支持

  • 定义多套环境
  • 启用默认环境
  • 开发时切换环境
  • 打包切换环境

SpringBoot测试

@RunWith(SpringRunner.class)
@SpringBootTest(classes = App.class)
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容