Spring Boot 2.5.6 catch 22 with spring.profiles.active

Viewed 1750

I am updating a web app from Spring Boot 2.2.4 to 2.5.6 and have used Open Rewrite to handle the tedium. The run configuration in IntelliJ has spring-boot:run -Dspring.profiles.active=local -f pom.xml in the command line (this has been working with 2.2.4). After adding a try/catch to main, to actually learn why I kept getting exit code 1 with no additional info, I found java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.profiles.active' in value "classpath:application-${spring.profiles.active}.properties" to be the root issue.

Apparently passing local on the command line for spring.profiles.active is now ignored… So, I added it to application.yml which gives me a message about how it is invalid to use spring.profiles.active. I found that the currently active profile should now be in config.activate.on-profile.active so I switched to that and then did a project wide search for spring.profiles.active and replaced every single instance with config.activate.on-profile.active.

I ran the project again and again got the message that it could resolve the placeholder spring.profiles.active! I can't for the life of me figure out where that placeholder is coming from since it doesn't exist anywhere in the project now according to IntelliJ, not even in the ReadMe file!

Is there some secret place I need to look to purge this old placeholder from existence?

1 Answers

I ran into the same issue and found a link to a github issue where a workaround was provided. Create a class:

public class JunitProfileResolver implements ActiveProfilesResolver {

  private static final String PROFILE_JUNIT = "test";

  @Override
  public String[] resolve(Class<?> testClass) {
    System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, PROFILE_JUNIT);
    return new String[] { PROFILE_JUNIT };
  }
}

And use it like:

@ActiveProfiles(profiles = "test", resolver = JunitProfileResolver.class)
public class MyTest {

For me this solves the problem.

Related