2

I can't activate the Spring download profile in IntelliJ IDEA.

Java 17

IntelliJ IDEA 2021.3 Beta (Ultimate Edition)

<spring.version>5.3.9</spring.version>

I'm coming in Run | Edit Configurations... and in VM options I prescribe

-Dspring.profiles.active=development

And when you start the application from the IDE, the following error crashes:

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

At the same time, I managed to launch it manually with this option:

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

What else do I need to register in the IDE that I missed? I cleaned the cache. Rechecked all the settings. Nothing helps. I don't understand what the problem might be. At the same time, other project developers do not have this problem. With the -Spring.profiles.active=development flag, the application is launched in IDEA

profile in Pom.xml This is a shared file Pom.xml, which is at the root of the entire project on microservices.

<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>

And this is the file pom.xml the microservice I'm trying to run.

  <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>

enter image description here enter image description here

File application.yaml

spring.config.activate.on-profile: development
alex
  • 324
  • 1
  • 8
  • 28
  • Hello. Please see: [Do posts have to be in English on Stack Exchange?](https://meta.stackexchange.com/q/13676) Use [edit] option and translate it to English OR move it (delete it from here and repost in proper place) to appropriate StackExchange site which is using your language (if such exists - visit first link in this comment to find list of sites about programming problems in other languages). – Pshemo Nov 07 '21 at 12:36
  • 1
    Why do you use `-Dspring.profiles.active=development` as the VM options but you use `--spring.profiles.active=development` in command line as the argument? The command line argumentas are specified in Run/Debug Configurations | **Program arguments:** field in the IDE. – Andrey Nov 09 '21 at 08:08
  • Because in similar questions on this site, it is recommended to use VM options -Spring.profiles.active=development And on the command line, by trial and error, I managed to launch the application with the --spring.profiles.active=development option. I tried using this option in VM, but nothing came out of it – alex Nov 09 '21 at 10:00
  • can you push the project in GitHub and share the link for the same? – dassum Nov 14 '21 at 05:14
  • can you please try with the environment variable SPRING_PROFILES_ACTIVE=development in IntelliJ – dassum Nov 14 '21 at 05:17
  • I added pom.xml is this it? – alex Nov 14 '21 at 05:36
  • This should work if you put the `-Dspring.profiles.active=development` argument in the VM options section. In addition, if you use the spring boot run configuration, there is an "Active profiles" section at the bottom. So, if you're still experiencing problems, there's something else wrong, and we need more information such as a screenshot of your run configuration in IntelliJ. – g00glen00b Nov 15 '21 at 14:59
  • I added a picture. Is this what you wanted? – alex Nov 15 '21 at 15:22
  • I don't understand what configuration you are talking about. Information from the pom.xml I provided. I run the project using IDEA tools. I run only this microservice for execution. Please write in more detail what configuration you need. – alex Nov 16 '21 at 04:40
  • You are mixing Spring Boot profiles and Maven profiles. What do you want to do? – Simon Martinelli Nov 16 '21 at 13:10
  • And added a description that this is a shared file. – alex Nov 16 '21 at 13:18
  • https://stackoverflow.com/a/39775038/8312604 – Alexandr Arhipov Nov 20 '21 at 10:57

2 Answers2

2

The Profile you define in your pom.xml is a maven build profile, which has nothing to do with a spring config-property profile.

maven-profile:https://maven.apache.org/guides/introduction/introduction-to-profiles.html
spring-profile: https://docs.spring.io/spring-boot/docs/2.6.x/reference/html/features.html#features.profiles

spring.config.activate.on-profile: development turns the current document of the configuration off if none of the active profiles is named development. So, this is like a filter for config-properties.

And you don't have to tell spring all profiles that will be used. So that line makes only sense if the document contains some application properties you want to turn on or off. These profiles are controlled via the launch configuration in IntelliJ.

For the maven-profile, you can enable/disable them in IntelliJs maven tab.
See: Work with maven profiles

3Fish
  • 640
  • 3
  • 18
  • You can add settings there. But all my settings are the same as yours. I added information from the application file.yaml, where the profile is specified. I specified the IDEA version, it is the most recent. – alex Nov 16 '21 at 13:08
0

I am not sure if the latest Intellij Ultimate has changed the UI. I normally set the active profile from Edit Configuration > under Enviromnet > Active Profile (for 2020 Intellij version), put your profile name there, and save it. remove -Dspring.profiles.active=development and then try

make sure you have a spring property file with the name application-development.properties or application-development.yml in your project

newcoder
  • 464
  • 9
  • 23