Skip to content

Command registration differs with @ActiveProfiles in tests vs jar spring.profiles.active= (4.0.1) #1327

@fietser97

Description

@fietser97

We have an application with 2 profiles. (this worked in version 3)

  1. The behavior between @activeprofiles and spring.profiles.active= is different. Where we would not expect this.
  2. When using spring.profiles.active= we get application failed to start because it tries to autoconfigure a command it shouldn't

When we run tests we start the application with @activeprofiles("profileName") this works like expected.
When we run the application with java jar spring.profiles.active="profileName" - jar app.jar we get the following exception. (see at the end)
Even though in our profile it should not try to load this command and this "beanName".

How to reproduce:

  • Create an spring shell application
  • Create 2 spring profiles that load separate packages
  • Try to run the jar with spring.profiles.active=

GOAL

  • Make @ActiveProfile and spring.profiles.active= behave the same way
  • Make spring.profiles.active= not load commands that are not within the active profiles components.

one profile config:

@Configuration
@Profile("profileName")
@ComponentScan(basePackages = "com.example.profileName")
public class profileNameConfiguration {
}

Test with profile:

@ActiveProfiles("profileName")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
        classes = {Application.class},
        args = "helloWorld")
@ExtendWith(OutputCaptureExtension.class)
class ProfileTest {

    @Test
    void testCommandOutput(CapturedOutput output) {
        assertThat(output).contains("Hello world!");
    }
}

Log when running with profile:

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
ERROR 21 --- [main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Method commandRegistry in org.springframework.shell.core.autoconfigure.CommandRegistryAutoConfiguration required a bean of type 'beanName' that could not be found.


Action:

Consider defining a bean of type 'BeanName in your configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/need-triageTeam needs to triage and take a first look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions