Skip to content

Tests with ActiveProfiles annotation cannot resolve placeholder 'spring.profiles.active' #21631

@andrewdroz

Description

@andrewdroz

With version Spring Boot version 2.3.0.RELEASE, tests annotated with @ActiveProfiles("test") fail to resolve variable spring.profiles.active.

The issue is not present on version 2.2.7.RELEASE.

It can be reproduced with a simple Spring Boot app created from Spring Initializr with options:

  • Maven Project
  • Java
  • Spring Boot 2.3.0
  • Packaging Jar
  • Java 8
  • No dependencies

The code to add are a Config class, @ActiveProfiles on the test class, and a application-test.properties file (empty contents).

Config class

package com.example.demo;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource(
    ignoreResourceNotFound = false,
    value = "classpath:application-${spring.profiles.active}.properties")
public class Config {}

Test file with @activeprofiles

@SpringBootTest
@ActiveProfiles("test")
class DemoApplicationTests {

	@Test
	void contextLoads() {}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by anothertheme: config-dataIssues related to the configuration theme

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions