基于maven的springboot的"过时"用法解析

 更新时间:2023年09月18日 08:37:37   作者:codecraft  
这篇文章主要为大家介绍了基于maven的springboot"过时"用法示例解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

接触过许多工程,发现有一些基于maven的springboot工程还是使用maven的profile,有些"过时"了,下面简单介绍一下。

示例1

pom.xml
<profiles>
        <profile>
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <profiles.active>test</profiles.active>
            </properties>
        </profile>
        <profile>
            <id>staging</id>
            <properties>
                <profiles.active>staging</profiles.active>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <profiles.active>prod</profiles.active>
            </properties>
        </profile>
    </profiles>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <configuration>
                    <target>1.8</target>
                </configuration>
                <executions>
                    <execution>
                        <id>copy-service-properties</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <copy todir="target/classes/config" overwrite="true">
                                    <fileset dir="${basedir}/src/main/resources/deploy/${profiles.active}">
                                        <include name="*.yml"/>
                                    </fileset>
                                </copy>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
src/main/resources
├── config
│   ├── application.yml
│   └── bootstrap.yml
├── deploy
│   ├── Dockerfile
│   ├── dev
│   │   ├── application.yml
│   │   └── bootstrap.yml
│   ├── prod
│   │   ├── application.yml
│   │   └── bootstrap.yml
│   ├── staging
│   │   ├── application.yml
│   │   └── bootstrap.yml
│   └── test
│       ├── application.yml
│       └── bootstrap.yml

 这种方法呢,感觉是多此一举,用application-{profile}.yml不香吗,感觉是没有用上springboot之前的maven工程的用法

示例2

pom.xml
<profiles>
        <profile>
            <id>dev</id>
            <properties>
                <app.active>dev</app.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <app.active>test</app.active>
            </properties>
        </profile>
        <profile>
            <id>staging</id>
            <properties>
                <app.active>staging</app.active>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <app.active>prod</app.active>
            </properties>
        </profile>
    </profiles>
application.yml
spring:
  profiles:
    active: @app.active@

 这种用法呢,src/main/resources下面只有一个application.yml,把profile的差异放到了maven的profile中,在application.yml引用maven的profile变量,有点"少见多怪",直接application-{profile}.yml用不香吗。

小结

springboot工程已经提供了profile的特性了,其实大部分场景可以替换掉maven的profile,没必要在使用maven的profile了,不然总感觉显得有点古老和过时。

以上就是基于maven的springboot的"过时"用法的详细内容,更多关于maven的springboot的"过时"用法的资料请关注脚本之家其它相关文章!

相关文章

  • JSON Web Token(JWT)原理入门教程详解

    JSON Web Token(JWT)原理入门教程详解

    这篇文章主要为大家介绍了JSON Web Token(JWT)原理入门教程详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步早日升职加薪
    2022-04-04
  • mybatis-plus复合主键的使用

    mybatis-plus复合主键的使用

    本文主要介绍了mybatis-plus复合主键的使用,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-03-03
  • 如何将maven源改为国内阿里云镜像

    如何将maven源改为国内阿里云镜像

    在使用Maven打包Scala程序时,默认是从位于国外的Maven中央仓库下载相关的依赖,造成我们从国内下载依赖时速度很慢,下面这篇文章主要给大家介绍了关于如何将maven源改为国内阿里云镜像的相关资料,需要的朋友可以参考下
    2023-02-02
  • Spring中@order注解用法实战教程

    Spring中@order注解用法实战教程

    @Order注解主要用来控制配置类的加载顺序,数字越小,越先加载,下面这篇文章主要给大家介绍了关于Spring中@order注解用法的相关资料,需要的朋友可以参考下
    2022-11-11
  • 一篇文章带你了解Java SpringBoot Nacos

    一篇文章带你了解Java SpringBoot Nacos

    这篇文章主要介绍了SpringBoot使用Nacos配置中心的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-09-09
  • java如何确定一个链表有环及入口节点

    java如何确定一个链表有环及入口节点

    这篇文章主要介绍了java如何确定一个链表有环及入口节点,想了解数据结构的同学可以参考下
    2021-04-04
  • BigDecimal的加减乘除计算方法详解

    BigDecimal的加减乘除计算方法详解

    小编做题遇到了大数的精确计算,再次认识了bigdecimal关于Bigdecimal意外的有许多小知识点和坑,这里特此整理一下为方便以后学习,希望能帮助到其他的萌新
    2021-08-08
  • Android中Parcelable的作用实例解析

    Android中Parcelable的作用实例解析

    这篇文章主要介绍了Android中Parcelable的作用,对于Android初学者有一定的参考学习价值,需要的朋友可以参考下
    2014-08-08
  • Java concurrency之AtomicReference原子类_动力节点Java学院整理

    Java concurrency之AtomicReference原子类_动力节点Java学院整理

    AtomicReference是作用是对"对象"进行原子操作。这篇文章主要介绍了Java concurrency之AtomicReference原子类,需要的朋友可以参考下
    2017-06-06
  • Springboot中实现接口幂等性的4种方案小结

    Springboot中实现接口幂等性的4种方案小结

    本文主要介绍了Springboot中实现接口幂等性,包含数据库的幂等,数据库的幂等,Redis的幂等性和Token + 时间戳的幂等性,具有一定的参考价值,感兴趣的可以了解一下
    2024-03-03

最新评论