springboot maven多环境打包配置

本文详细介绍如何在Spring Boot项目中使用Maven进行多环境配置,包括开发(dev)、生产(prd)和测试(test)环境的自动切换。通过定义profiles和使用占位符,实现不同环境下的资源配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

resources下的文件:application.yml、application-dev.yml、application-prd.yml和application-test.yml。
通过配置application.yml下spring:profiles:active:的值来使用不同的配置文件。
application.yml如下:

spring:
  profiles: #此处为占位符,maven打包时会自动替换为实际使用的配置文件
    active: #spring.profiles.active#
  cache:
    type: redis
pagehelper:
  supportMethodsArguments: true
  reasonable: true
  helperDialect: mysql
  params: count=countSql
mybatis:
  type-aliases-package: com.tianren.bean
  mapper-locations: classpath:mapper/*.xml
mapper:
  identity: MYSQL

上面用了#作为占位符,因为$在maven中已经被定义为取变量的符号了。
再看maven中的配置:

<!-- maven多环境打包配置 -->
  <profiles>
    <!-- 开发环境 -->
    <profile>
      <id>dev</id>
      <properties>
        <spring.profiles.active>dev</spring.profiles.active>
      </properties>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
    </profile>
    <!-- 生产环境 -->
    <profile>
      <id>prd</id>
      <properties>
        <spring.profiles.active>prd</spring.profiles.active>
      </properties>
    </profile>
    <!-- 测试环境 -->
    <profile>
      <id>test</id>
      <properties>
        <spring.profiles.active>test</spring.profiles.active>
      </properties>
    </profile>
  </profiles>

  <build>
    <plugins>
      <!-- 其他配置将从父pom继承 -->
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <!-- maven多环境打包资源过滤插件 -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>default-resources</id>
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>target/classes</outputDirectory>
              <useDefaultDelimiters>false</useDefaultDelimiters>
              <delimiters>
                <delimiter>#</delimiter>
              </delimiters>
              <resources>
                <resource>
                  <directory>src/main/resources/</directory>
                  <filtering>true</filtering>
                  <includes>
                    <include>**/*.yml</include>
                  </includes>
                </resource>
                <resource>
                  <directory>src/main/resources/</directory>
                  <filtering>false</filtering>
                  <excludes>
                    <exclude>**/*.yml</exclude>
                  </excludes>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- 此插件解决资源过滤器bug -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <dependencies>
          <dependency>
            <groupId>org.apache.maven.shared</groupId>
            <artifactId>maven-filtering</artifactId>
            <version>3.1.1</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

上面首先定义了一组profiles。注意properties里面的标签名应该与application.yml中占位符之间的内容一样!
delimiter定义了一个占位符。
resources里面定义了需要过滤的文件已经不需要过滤的文件。像上面那样配置,maven打包时会检查resources下面所有以.yml结尾的文件,遇到#spring.profiles.active#则替换为实际的值。
这个值若在打包命令中不指定则以profiles中activeByDefault为true的为准。
若要在打包命令中指定,可以这样:

mvn clean package -P prd -Dmaven.test.skip=true;

-P 后面的参数就是要使用的配置名称。
后面的参数-Dmaven.test.skip=true也必须要有,不然运行maven测试会报错。

Vue3 + TypeScript (简称V3TS) 是结合了 Vue.js 的下一代版本和 TypeScript 这种强类型的 JavaScript 变体来构建应用的技术组合。手撕甘特图通常是一个时间线视图,用于展示项目的进度、任务分配或计划安排。在 V3TS 中制作甘特图,你可以遵循以下步骤: 1. **环境配置**:首先,确保已安装 Vue CLI v3,并设置支持 TypeScript。可以使用命令 `vue create` 创建一个新的 Vue3项目并选择 TypeScript 作为配置。 2. **引入库**:由于甘特图需要数据驱动,你可能需要引入第三方库如 `antv-g6` 或者 `vis` 来处理图形绘制。通过npm或yarn添加依赖。 3. **声明组件**:创建 TypeScript 类型化的组件,例如 `TaskItem.vue`,其中包含任务对象的数据类型 (`Task`) 和方法 (`generateGanttGraph()`). ```typescript import { Component, Prop } from 'vue'; interface Task { id: number; name: string; start: Date; end: Date; } @Component({ // ... }) export default class TaskItem extends Vue { @Prop() task: Task; generateGanttGraph(): void { // 使用甘特图库生成图表逻辑 } } ``` 4. **数据绑定**:在组件内部或父组件中,管理任务列表 (`Task[]`) 并将其绑定到视图上,以便更新显示。 5. **渲染图表**:在组件的模板部分,利用甘特图库提供的 API 渲染任务节点,传递任务数据。 6. **事件监听**:为了动态调整和交互,可以添加事件监听器,比如拖拽、点击事件等。 7. **样式定制**:用 CSS 样式美化甘特图,使其符合项目的视觉风格。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值