You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ IDEA配置VM参数激活Spring Boot profile报找不到主类VM如何解决

问题描述

我在IntelliJ IDEA中无法激活Spring profile,环境信息如下:

  • JDK版本:Java 17
  • IDE版本:IntelliJ IDEA 2021.3 Beta(旗舰版)
  • Spring版本:
<spring.version>5.3.9</spring.version>

我通过路径「运行 | 编辑配置...」进入配置页,在VM选项中填写了如下参数:

-Dspring.profiles.active=development

从IDE启动应用时抛出以下错误:

Error: Could not find or load main class VM
Caused by: java.lang.ClassNotFoundException: VM

但使用相同参数手动执行命令可以正常启动:

java -jar main-ms-1.2-SNAPSHOT.jar --spring.profiles.active=development

我已经清理了IDE缓存,反复核对所有配置都没有解决问题,项目其他开发者使用相同参数可以正常在IDEA中启动应用。相关配置文件内容如下:

项目根目录公共Pom.xml的profile配置

<profiles>
    <profile>
      <id>development</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <build.profile.id>development</build.profile.id>
        <maven.file.path>file:${project.basedir}/../../../maven</maven.file.path>
        <releases.maven.repository.url>${maven.file.path}/releases</releases.maven.repository.url>
        <snapshots.maven.repository.url>${maven.file.path}/snapshots
        </snapshots.maven.repository.url>
        <docker.registry.domain>localhost:5000</docker.registry.domain>
        <docker.registry.url>http://${docker.registry.domain}</docker.registry.url>
      </properties>
    </profile>
</profiles>

待启动微服务的pom.xml配置

<dependencies>
    <dependency>
      <groupId>com.asvoip.ump</groupId>
      <artifactId>ump-it-lib</artifactId>
      <version>1.1-SNAPSHOT</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.asvoip.ump</groupId>
      <artifactId>ump-currencymanager-api</artifactId>
      <version>1.2-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>com.asvoip.ump</groupId>
      <artifactId>ump-sqldbclient-lib</artifactId>
      <version>1.2-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>com.asvoip.ump</groupId>
      <artifactId>ump-restapiserver-lib</artifactId>
      <version>1.1-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>com.asvoip.ump</groupId>
      <artifactId>ump-documentation-lib</artifactId>
      <version>1.1-SNAPSHOT</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-starter-client</artifactId>
    </dependency>
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-boot-starter</artifactId>
    </dependency>

    <dependency>
      <groupId>co.elastic.logging</groupId>
      <artifactId>logback-ecs-encoder</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.dataformat</groupId>
      <artifactId>jackson-dataformat-xml</artifactId>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

配置截图

配置截图1
配置截图2

application.yaml配置内容

spring.config.activate.on-profile: development

请问我还遗漏了哪些IDE配置需要调整?


解决方案

你遇到的Could not find or load main class VM错误本质是IDEA将VM字符识别为了要启动的主类名,按以下步骤排查调整即可:

  1. 清空运行配置中的VM选项输入框所有内容,重新输入-Dspring.profiles.active=development,注意不要带入输入框的灰色提示文字,也不要额外添加VM前缀字符。
  2. 确认参数填写位置正确:2021.3版本的IDEA运行配置界面中,该参数需要填写在修改选项 -> 添加VM选项后出现的VM参数输入框中,不要填到「程序实参」或「环境变量」输入框内。
  3. 检查运行配置的「缩短命令行」选项,选择@argfile (Java 9+)即可,你的JDK 17版本适配该选项,可避免命令行解析异常。
  4. 上述操作完成后直接启动运行配置即可生效,无需额外调整项目pom或Spring配置文件。

内容的提问来源于stack exchange,提问作者alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 07:24:02