springboot多模块、多环境部署下,由relativePath标签带来的选择环境打包失败,总是打包默认环境的问题

1、**问题产生的原因:
使用idea工具,创建springboot多模块项目时候,new-project

 

 

 

然后创建出来的项目,在pom中有这这么一段配置
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    如果是子module,这段话要修改成继承自己父项目的POM。
    如果是父亲项目,我保留了这个配置
    并且在父项目中配置了多profiles
    <profiles>
        <profile>
            <!-- 本地开发环境 -->
            <id>dev</id>
            <properties>
                <!-- 这里的标签名会和resourse进行拼接 -->
                <activatedProperties>dev</activatedProperties>
            </properties>
            <!-- 这里配置为默认选项 -->
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <!-- 测试环境 -->
            <id>test</id>
            <properties>
                <activatedProperties>test</activatedProperties>
            </properties>
        </profile>
        <profile>
            <!-- 生产环境 -->
            <id>prod</id>
            <properties>
                <activatedProperties>prod</activatedProperties>
            </properties>
        </profile>
    </profiles>

2、后来因为增加了新的环境,父POM中增加了新的profile 如下
<profiles>
        <profile>
            <!-- 本地开发环境 -->
            <id>dev</id>
            <properties>
                <!-- 这里的标签名会和resourse进行拼接 -->
                <activatedProperties>dev</activatedProperties>
            </properties>
            <!-- 这里配置为默认选项 -->
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <!-- 测试环境 -->
            <id>test</id>
            <properties>
                <activatedProperties>test</activatedProperties>
            </properties>
        </profile>
        <profile>
            <!-- 测试环境 -->   /**新增加的环境配置文件名称
            <id>test-hz</id>
            <properties>
                <activatedProperties>test-hz</activatedProperties>
            </properties>
        </profile>

        <profile>
            <!-- 生产环境 -->
            <id>prod</id>
            <properties>
                <activatedProperties>prod</activatedProperties>
            </properties>
        </profile>
    </profiles>
    然后在测试环境部署项目,选择新增加的配置文件test-hz
    使用打包语句  mvn clean package -P test-hz
    然后打包报
    The requested profile "test-hz" could not be activated because it does not exist.
    找不到新增加的profile ,但是我POM中已经增加了环境,并且配置文件也存在。
    3、以上问题出现的原因是因为父POM中的relativePath 这个标签。
    这个标签如果不写,是默认采用项目路径中的父POM作为jar依赖依据。但是如果是写了一个空标签,我就是写了一个空标签<relativePath/> <!-- lookup parent from repository -->,那么maven在打包的时候,是始终从远端仓库获取POM的,而远端仓库中,我没有增加test-hz的profile,所以一直是找不到test-hz这个环境配置。而是采用了dev作为默认的环境进行配置
    4、解决办法,删除掉父POM中relativePath 这个标签。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要配置Spring Boot Vue的开发环境,需要进行以下步骤: 1. 安装Node.js和npm 2. 安装Vue CLI 3. 创建Vue项目 4. 配置Vue项目与Spring Boot项目的联合开发 具体步骤如下: 1. 安装Node.js和npm Node.js是一个基于Chrome V8引擎的JavaScript运行环境,可以使JavaScript在服务器端运行。npm是Node.js的包管理器,用于安装和管理Node.js模块。在安装Vue CLI之前,需要先安装Node.js和npm。可以在Node.js官网下载安装包进行安装。 2. 安装Vue CLI Vue CLI是一个基于Vue.js的快速开发工具,可以帮助我们快速创建Vue项目。可以使用npm安装Vue CLI,命令如下: ``` npm install -g @vue/cli ``` 3. 创建Vue项目 使用Vue CLI创建Vue项目非常简单,只需要执行以下命令即可: ``` vue create my-project ``` 其中,my-project是项目名称,可以根据实际情况进行修改。在创建项目时,可以选择手动配置或者使用默认配置。如果选择手动配置,则需要根据实际情况进行配置。 4. 配置Vue项目与Spring Boot项目的联合开发 在Vue项目中,可以使用axios等工具与后端进行交互。在Spring Boot项目中,可以使用@RestController注解将Java类转换为RESTful API。在Vue项目中,可以使用Vue Router等工具进行路由管理。在Spring Boot项目中,可以使用Spring MVC进行路由管理。可以将Vue项目打包成静态资源,然后将其放置在Spring Boot项目的src/main/resources/static目录下,这样就可以通过Spring Boot项目的URL访问Vue项目了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值