You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Command registration differs with @ActiveProfiles in tests vs jar spring.profiles.active= (4.0.1)Β #1327
We have an application with 2 profiles. (this worked in version 3)
The behavior between @activeprofiles and spring.profiles.active= is different. Where we would not expect this.
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.
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.
changed the title [-]Command registration differs with @ActiveProfiles in tests vs jar spring.profiles.active=[/-][+]Command registration differs with @ActiveProfiles in tests vs jar spring.profiles.active= (4.0.1)[/+]on Mar 4, 2026
packageorg.springframework.shell.samples.helloworld.boot;
importorg.springframework.boot.SpringApplication;
importorg.springframework.boot.autoconfigure.SpringBootApplication;
importorg.springframework.shell.core.command.annotation.Command;
importorg.springframework.shell.core.command.annotation.Option;
@SpringBootApplicationpublicclassSpringShellApplication {
publicstaticvoidmain(String[] args) {
SpringApplication.run(SpringShellApplication.class, args);
}
@Command(name = "hello", description = "Say hello to a given name", group = "Greetings",
help = "A command that greets the user with 'Hello ${name}!'. Usage: hello [-n | --name]=<name>")
publicvoidsayHello(@Option(shortName = 'n', longName = "name", description = "the name of the person to greet",
defaultValue = "World") Stringname) {
System.out.println("Hello " + name + "!");
}
}
packageorg.springframework.shell.samples.helloworld.profile;
importorg.springframework.shell.core.command.annotation.Command;
importorg.springframework.stereotype.Component;
@ComponentpublicclassProfileCommands {
@Command(name = "profileCommand",
description = "A command that is only available when the 'profileName' profile is active")
publicvoidprofileCommand() {
System.out.println("This command is only available when the 'profileName' profile is active");
}
}
Running without profile - profileCommand is NOT available (as expected)
I am not sure if this is your precise configuration but from your description it seems like it is. Could you share a minimal reproducer project or the exact configuration/classes that cause the issue? That would help me pinpoint the problem.
sorry, my explanation wasn't clear enough.
We have 2 profiles. So,
profile 1
package org.springframework.shell.samples.helloworld.boot;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
@Profile("profileName")
@ComponentScan(basePackages = "org.springframework.shell.samples.helloworld.profile")
public class ProfileNameConfiguration {
}
and anotherProfile
package org.springframework.shell.samples.helloworld.boot;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
@Profile("anotherProfileName")
@ComponentScan(basePackages = "org.springframework.shell.samples.helloworld.anotherProfile")
public class anotherProfileNameConfiguration {
}
then have
package org.springframework.shell.samples.helloworld.profile;
import org.springframework.shell.core.command.annotation.Command;
import org.springframework.stereotype.Component;
@Component
public class ProfileCommands {
@Command(name = "profileCommand",
description = "A command that is only available when the 'profileName' profile is active")
public void profileCommand() {
System.out.println("This command is only available when the 'profileName' profile is active");
}
}
and
package org.springframework.shell.samples.helloworld.profile;
import org.springframework.shell.core.command.annotation.Command;
import org.springframework.stereotype.Component;
@Component
public class AnotherProfileCommands {
@Command(name = "anotherCommand",
description = "A command that is only available when the 'anotherProfileName' profile is active")
public void anotherCommand() {
System.out.println("This command is only available when the 'anotherProfileName' profile is active");
}
}
Though we think that #1329 will fix our issue. Of having just 1 profile set. IF you set more profiles at once it might still break.
After this version is released we can test it for you. If the above doesn't work out :)
However, I am not able to reproduce the issue with the latest main branch. In fact, only the commands of the active profile are registered. Here is the complete minimal sample:
IF you set more profiles at once it might still break.
Tested this as well, and things work as expected: I get the commands of both active profiles:
14:47:50.138 [main] INFO o.s.s.s.h.b.SpringShellApplication - Starting SpringShellApplication using Java 17.0.17 with PID 36511 (/Users/mbh/projects/spring-shell/spring-shell-samples/spring-shell-sample-spring-boot/target/classes started by mbh in /Users/mbh/projects/spring-shell)
14:47:50.139 [main] INFO o.s.s.s.h.b.SpringShellApplication - The following 2 profiles are active: "profileName", "anotherProfileName"
14:47:50.346 [main] INFO o.h.validator.internal.util.Version - HV000001: Hibernate Validator 9.0.1.Final
14:47:50.775 [main] WARN org.jline - Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
14:47:50.840 [main] INFO o.s.s.s.h.b.SpringShellApplication - Started SpringShellApplication in 0.821 seconds (process running for 1.054)
shell:>help
AVAILABLE COMMANDS
Another Profile Commands
anotherCommand: A command that is only available when the 'anotherProfileName' profile is active
Built-In Commands
clear: Clear the terminal screen
help: Display help about available commands
history: Display or save the history of previously run commands
quit, exit: Exit the shell
script: Execute commands from a script file
version: Show version info
Profile Commands
profileCommand: A command that is only available when the 'profileName' profile is active
shell:>
I believe this issue is fixed with the combination of 236dbc9 and 56cf581, which should be shipped in the upcoming 4.0.2.
Activity
[-]Command registration differs with @ActiveProfiles in tests vs jar spring.profiles.active=[/-][+]Command registration differs with @ActiveProfiles in tests vs jar spring.profiles.active= (4.0.1)[/+]czpilar commentedon Apr 3, 2026
Hello, I've just tried to reproduce this issue but I am unable to reproduce it. Here is the configuration I have tried:
Project structure
SpringShellApplication.javaProfileNameConfiguration.javaProfileCommands.javaRunning without profile -
profileCommandis NOT available (as expected)Running with profile -
profileCommandIS available (as expected)Or equivalently:
Test with
@ActiveProfiles- works as expectedI am not sure if this is your precise configuration but from your description it seems like it is. Could you share a minimal reproducer project or the exact configuration/classes that cause the issue? That would help me pinpoint the problem.
fietser97 commentedon Apr 7, 2026
sorry, my explanation wasn't clear enough.
We have 2 profiles. So,
profile 1
and anotherProfile
then have
and
Though we think that #1329 will fix our issue. Of having just 1 profile set. IF you set more profiles at once it might still break.
After this version is released we can test it for you. If the above doesn't work out :)
fmbenhassine commentedon Apr 7, 2026
@fietser97 I confirm the issue with 4.0.1: Here is a minimal reproducer:
demo-gh1327-shell-4.0.1.zip
However, I am not able to reproduce the issue with the latest
mainbranch. In fact, only the commands of the active profile are registered. Here is the complete minimal sample:spring-shell-sample-spring-boot-gh1327.zip
Tested this as well, and things work as expected: I get the commands of both active profiles:
I believe this issue is fixed with the combination of 236dbc9 and 56cf581, which should be shipped in the upcoming 4.0.2.
@czpilar Many thanks for the follow up on this!
fietser97 commentedon Apr 7, 2026
Perfect, thanks for letting me know. Happy that it's found and fixed.