• Spring Boot学习--spring-boot-starter-parent及starters(转)


    在官方文档的第三部分的13块讲述了引用的管理,官方推荐的是使用Maven和Gradle。

    我一直在用的是maven,而且使用maven有些优势–spring-boot-starter-parent,这个部件是maven独有的。

    这次我们从这里开始学习。

    Maven的用户可以通过继承spring-boot-starter-parent项目来获得一些合理的默认配置。这个parent提供了以下特性:

    默认使用Java 8
    使用UTF-8编码
    一个引用管理的功能,在dependencies里的部分配置可以不用填写version信息,这些version信息会从spring-boot-dependencies里得到继承。
    识别过来资源过滤(Sensible resource filtering.)
    识别插件的配置(Sensible plugin configuration (exec plugin, surefire, Git commit ID, shade).)
    能够识别application.properties和application.yml类型的文件,同时也能支持profile-specific类型的文件(如: application-foo.properties and application-foo.yml,这个功能可以更好的配置不同生产环境下的配置文件)。
    maven把默认的占位符${…​}改为了@..@(这点大家还是看下原文自己理解下吧,我个人用的也比较少
    since the default config files accept Spring style placeholders (${…​}) the Maven filtering is changed to use @..@ placeholders (you can override that with a Maven property resource.delimiter).)
    spring-boot-starter-parent的引用

    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.BUILD-SNAPSHOT</version>
    </parent>

    如果dependencies中的一些引用不想使用默认的版本,可以直接加上version信息,把默认的覆盖掉。

    另外官方提供的覆盖默认配置的方式如下:

    <properties>
        <spring-data-releasetrain.version>Fowler-SR2</spring-data-releasetrain.version>
    </properties>

    在properties中注明某个引用要使用的版本。具体使用哪种方式还是看个人习惯。

    如果不想使用spring-boot-starter-parent,也可以自己来配置所要使用的版本:

    <dependencyManagement>
         <dependencies>
            <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.0.0.BUILD-SNAPSHOT</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    但是,这种方式下如果想要某些引用的版本特殊说明,就要在上面的声明之前配置:

    <dependencyManagement>
        <dependencies>
            <!-- Override Spring Data release train provided by Spring Boot -->
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-releasetrain</artifactId>
                <version>Fowler-SR2</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.0.0.BUILD-SNAPSHOT</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    这里的引用声明是借助scope=import 来实现的。

    如果想要把项目打包成一个可执行的jar包,需要添加maven的一下组件:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    这里前边文章中都有说过,位置一般都是放在dependencies之后。


    ————————————————
    版权声明:本文为CSDN博主「月未明」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_35981283/article/details/77802771

  • 相关阅读:
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-qrcode
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-volume-up
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-volume-down
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-volume-off
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-headphones
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-flag
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-lock
    【codeforces 750F】New Year and Finding Roots
    【hdu 1517】A Multiplication Game
    json格式化和查看工具
  • 原文地址:https://www.cnblogs.com/muxi0407/p/12049670.html
Copyright © 2020-2023  润新知