【发布时间】:2021-12-20 15:27:15
【问题描述】:
我无法在 IntelliJ IDEA 中激活 Spring 下载配置文件。
Java 17
IntelliJ IDEA 2021.3 Beta(终极版)
<spring.version>5.3.9</spring.version>
我来了 Run |编辑配置... 在我规定的虚拟机选项中
-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 中注册什么? 我清理了缓存。重新检查了所有设置。没有什么帮助。我不明白问题可能是什么。同时,其他项目开发商不存在这个问题。使用 -Spring.profiles.active=development 标志,应用程序在 IDEA 中启动
Pom.xml 中的配置文件 这是一个共享文件Pom.xml,是整个微服务项目的根目录。
<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>
文件 application.yaml
spring.config.activate.on-profile: development
【问题讨论】:
-
你好。请参阅:Do posts have to be in English on Stack Exchange? 使用 edit 选项并将其翻译为英语或将其移动(从此处删除并重新发布到适当的位置)到使用您的语言的适当 StackExchange 站点(如果存在 - 请访问此评论中的第一个链接查找有关其他语言编程问题的网站列表)。
-
为什么你使用
-Dspring.profiles.active=development作为VM选项,而你在命令行中使用--spring.profiles.active=development作为参数?命令行参数在运行/调试配置中指定 | 程序参数: IDE 中的字段。 -
因为在此站点上的类似问题中,建议使用 VM 选项 -Spring.profiles.active=development 在命令行上,通过反复试验,我设法使用--spring.profiles.active=开发选项。我尝试在 VM 中使用此选项,但没有任何结果
-
你能在 GitHub 中推送项目并分享相同的链接吗?
-
能否请您在 IntelliJ 中使用环境变量 SPRING_PROFILES_ACTIVE=development 试试
标签: java spring-boot intellij-idea