[英]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 Ultimate 是否更改了 UI。 我通常從“ Edit Configuration > under Enviromnet > Active Profile
(對於 2020 Intellij 版本)下設置活動配置文件,將您的配置文件名稱放在那里,然后保存。 刪除-Dspring.profiles.active=development
然后嘗試
確保您的項目中有一個名為application-development.properties
或application-development.yml
的 spring 屬性文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.