簡體   English   中英

從 IntelliJ 啟動時無法激活 Spring 引導配置文件

[英]It is not possible to activate the Spring boot profile when starting from IntelliJ

我無法在 IntelliJ IDEA 中激活 Spring 下載配置文件。

爪哇 17

IntelliJ IDEA 2021.3 Beta(終極版)

<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 中注冊哪些我錯過的東西? 我清理了緩存。 重新檢查所有設置。 沒有任何幫助。 我不明白問題可能是什么。 同時,其他項目開發者沒有這個問題。 使用 -Spring.profiles.active=development 標志,應用程序在 IDEA 中啟動

在 Pom.xml 中的 profile 這是一個共享文件 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

我不知道您到底出了什么問題,但在我看來,您的運行配置窗口看起來與我的非常不同。 你有最新的 IntelliJ 版本嗎? 或者您使用的是一些自定義配置模板?

對我來說,必須設置以下內容才能使用配置文件。

  1. 配置文件應在應用程序屬性或 yaml 文件中定義。
  2. 通過將配置文件設置為默認值或通過應用程序配置激活,或在“Spring Boot”選項卡下指定的“活動配置文件”字段中的運行配置中將其設置來激活配置文件。
  3. 此外,“主類”字段應指向包含您要啟動的主函數的類。

我的運行配置

如果您想要更詳細的答案,則必須提供有關項目的更多信息,例如結構、應用程序配置文件、啟動配置中的所有配置等...

我不確定最新的 Intellij Ultimate 是否更改了 UI。 我通常從“ Edit Configuration > under Enviromnet > Active Profile (對於 2020 Intellij 版本)下設置活動配置文件,將您的配置文件名稱放在那里,然后保存。 刪除-Dspring.profiles.active=development然后嘗試

確保您的項目中有一個名為application-development.propertiesapplication-development.yml的 spring 屬性文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM