Environment :

  • Java 21
  • Spring Boot 3.4.x, 3.5.x
  • Dev on Windows 10 / Intellij (works)
  • Failed on Unix (RHEL 8)

Since Spring Boot 3.4.8 (it's works in 3.4.6 & 3.4.7, failed in 3.4.8; 3.5.3 and 3.5.4), my Spring Boot doesn't load environement variable profile and application.yaml.

Main class :

@Slf4j
@SpringBootApplication
@RequiredArgsConstructor
@EnableEncryptableProperties
@ConditionalOnNotWebApplication
public class ApplicationBatch implements CommandLineRunner {
    private final InstallService installService;
    private final LauncherService launcherService;
    private final RunService runService;

    public static void main(String... args) {
        new SpringApplicationBuilder(ApplicationBatch.class)
                .bannerMode(Banner.Mode.OFF)
                .web(WebApplicationType.NONE)
                .run(args);
    }

    /**
     * args[0] task params
     *
     * @param args Paramètre du traitement
     */
    @Override
    public void run(String... args) {
        JarRunnable runnable = runService.getJsonParameter(args, JarRunnable.class, "runnable");

        if (runnable.getKey().equals("install")) {
            runService.run(installService::install, args, InstallParameter.class);
        } else {
            runService.run(launcherService::launch, args, LauncherParameter.class);
        }
    }
}

Config class :

@Configuration
@RequiredArgsConstructor
@EnableConfigurationProperties(TechProperties.class)
public class TechConfiguration {
    @Bean
    public HikariDataSource dataSource(TechProperties techProperties) {
        return DatabaseUtils.createDataSource(techProperties.technicalDatabase());
    }

    @Bean
    public SpringLiquibase liquibase(@Qualifier("dataSource") HikariDataSource dataSource) {
        SpringLiquibase liquibase = new SpringLiquibase();
        liquibase.setChangeLog("classpath:changelog-master-init.yaml");
        liquibase.setDataSource(dataSource);
        liquibase.setDefaultSchema(dataSource.getSchema());

        return liquibase;
    }
}

Properties class

@ConfigurationProperties(prefix = "tech")
public record TechProperties(
        short defaultNbThreads,
        String defaultProtocol,
        String defaultHostname,
        String defaultPort,
        String defaultUsername,
        String defaultPassword,
        boolean enableInitSftp,
        boolean enableSchemaCheck,
        boolean enableConfigCheck,
        String directoryKey,
        String prefixDatabase,
        DataSourceConfig technicalDatabase,
        List<String> databases,
        Map<String, ApiInfo> apiMap,
        JavaProperties java
) {

}

On Windows environment with my Intellij's IDE it's works fine, but it's failed when I run it from jar file in bash command :

$ export SPRING_PROFILES_ACTIVE=d1
$ java --enable-preview -cp "$my_jar:$CONF:$SECURITY" fr.maif.datain.ApplicationBatch "$PARAMS"

Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
22:29:05.833 [main] INFO fr.maif.datain.ApplicationBatch -- Starting ApplicationBatch using Java 21.0.3 with PID 2998628 (/travail/sys0/data-ingest/temp/data-in-tech-1.0.0-SNAPSHOT-jar-with-dependencies.jar started by admxhd in /appli_tech/data-ingest/ksh/d1)
22:29:05.835 [main] INFO fr.maif.datain.ApplicationBatch -- **No active profile set, falling back to 1 default profile: "default"**
22:29:06.189 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate -- Bootstrapping Spring Data JPA repositories in DEFAULT mode.
22:29:06.226 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate -- Finished Spring Data repository scanning in 34 ms. Found 6 JPA repository interfaces.
22:29:06.335 [main] INFO com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesBeanFactoryPostProcessor -- Post-processing PropertySource instances
22:29:06.335 [main] INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter -- Skipping PropertySource configurationProperties [class org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource
22:29:06.336 [main] INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter -- Converting PropertySource commandLineArgs [org.springframework.core.env.SimpleCommandLinePropertySource] to EncryptableEnumerablePropertySourceWrapper
22:29:06.336 [main] INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter -- Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper
22:29:06.336 [main] INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter -- Converting PropertySource systemEnvironment [org.springframework.core.env.SystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper
22:29:06.336 [main] INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter -- Converting PropertySource applicationInfo [org.springframework.boot.ApplicationInfoPropertySource] to EncryptableMapPropertySourceWrapper
22:29:06.403 [main] WARN org.springframework.context.annotation.AnnotationConfigApplicationContext -- Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'dataSource' defined in class path resource [fr/maif/datain/config/TechConfiguration.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Cannot invoke "fr.maif.datain.data.DataSourceConfig.getJdbcUrl()" because "dataSourceConfig" is null
22:29:06.405 [main] ERROR org.springframework.boot.SpringApplication -- Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'dataSource' defined in class path resource [fr/maif/datain/config/TechConfiguration.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Cannot invoke "fr.maif.datain.data.DataSourceConfig.getJdbcUrl()" because **"dataSourceConfig" is null**

In stack trace, we can see Spring Boot can't find active profile (error 1) and don't load any properties (error 2)..

I tried to rename application-d1.yaml to application-d1.yml, application.yaml, application.properties... It's never works since Spring Boot 3.4.8.

I need to set up profile in initializer. And for properties, I need to set up @PropertySource(value= {"classpath:application.yaml", "classpath:application-d1.yaml"}) on TechProperties record.

Comment From: philwebb

@Maths37 Could you please provide a sample application that reproduces the problem. We've not had any other reports of such issues and I wonder if this is related to your use of com.ulisesbocchio.jasyptspringboot.

Comment From: Maths37

@Maths37 Could you please provide a sample application that reproduces the problem. We've not had any other reports of such issues and I wonder if this is related to your use of com.ulisesbocchio.jasyptspringboot.

Thanks for your reply. I removed jasypt and tried 3.4.8, fail again (banner console for the test) :

$ export SPRING_PROFILES_ACTIVE=d1
$ /usr/lib/jvm/jre-21/bin/java --enable-preview -cp "/travail/sys0/data-ingest/temp/data-in-tech-1.0.0-SNAPSHOT-jar-with-dependencies.jar:$CONF:$SECURITY" fr.maif.datain.ApplicationBatch "{}"
Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.8)

09:51:50.707 [main] INFO fr.maif.datain.ApplicationBatch -- Starting ApplicationBatch using Java 21.0.3 with PID 3031538 (/travail/sys0/data-ingest/temp/data-in-tech-1.0.0-SNAPSHOT-jar-with-dependencies.jar started by admxhd in /appli_tech/data-ingest/ksh/d1)
09:51:50.709 [main] INFO fr.maif.datain.ApplicationBatch -- **No active profile set, falling back to 1 default profile: "default"**
09:51:51.017 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate -- Bootstrapping Spring Data JPA repositories in DEFAULT mode.
09:51:51.057 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate -- Finished Spring Data repository scanning in 35 ms. Found 6 JPA repository interfaces.
09:51:51.208 [main] WARN org.springframework.context.annotation.AnnotationConfigApplicationContext -- Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'dataSource' defined in class path resource [fr/maif/datain/config/TechConfiguration.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Cannot invoke "fr.maif.datain.data.DataSourceConfig.getJdbcUrl()" **because "dataSourceConfig" is null**
09:51:51.209 [main] ERROR org.springframework.boot.SpringApplication -- Application run failed

Do you want I try something else or need more informations ?

Comment From: nosan

Could you please provide a sample application that reproduces the problem? You can use https://start.spring.io/ to generate a new project with minimal setup that demonstrates the issue. Ideally, it should be something that can be run locally to reproduce the same problem you are seeing. Feel free to either attach a ZIP file or share a link to a GitHub repository that can be downloaded and run.

Thanks!

Comment From: Maths37

Could you please provide a sample application that reproduces the problem? You can use https://start.spring.io/ to generate a new project with minimal setup that demonstrates the issue. Ideally, it should be something that can be run locally to reproduce the same problem you are seeing. Feel free to either attach a ZIP file or share a link to a GitHub repository that can be downloaded and run.

Thanks!

I reproduced bug with sample application, git : https://github.com/Maths37/test-bug

$ export SPRING_PROFILES_ACTIVE=bug
$ /usr/lib/jvm/jre-21/bin/java -cp "/travail/sys0/data-ingest/temp/test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar:$CONF" fr.maif.test.bug.BugApplication

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.8)

10:48:39.090 [main] INFO fr.maif.test.bug.BugApplication -- Starting BugApplication using Java 21.0.3 with PID 3036433 (/travail/sys0/data-ingest/temp/test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar started by admxhd in /appli_tech/data-ingest/ksh/d1)
10:48:39.091 [main] INFO fr.maif.test.bug.BugApplication -- No active profile set, falling back to 1 default profile: "default"
10:48:39.321 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate -- Bootstrapping Spring Data JPA repositories in DEFAULT mode.
10:48:39.331 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate -- Finished Spring Data repository scanning in 6 ms. Found 0 JPA repository interfaces.
Main yaml : null
Profile yaml : null
10:48:39.437 [main] WARN org.springframework.context.annotation.AnnotationConfigApplicationContext -- Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'dataSource' defined in class path resource [fr/maif/test/bug/config/BugConfiguration.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: null

$ export SPRING_PROFILES_ACTIVE=bug
$ /usr/lib/jvm/jre-21/bin/java -cp "/travail/sys0/data-ingest/temp/test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar:$CONF" fr.maif.test.bug.BugApplication

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.7)

2025-08-15T10:49:31.133+02:00  INFO 3036543 --- [test-bug] [           main] fr.maif.test.bug.BugApplication          : Starting BugApplication using Java 21.0.3 with PID 3036543 (/travail/sys0/data-ingest/temp/test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar started by admxhd in /appli_tech/data-ingest/ksh/d1)
2025-08-15T10:49:31.134+02:00  INFO 3036543 --- [test-bug] [           main] fr.maif.test.bug.BugApplication          : The following 1 profile is active: "bug"
2025-08-15T10:49:31.392+02:00  INFO 3036543 --- [test-bug] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2025-08-15T10:49:31.401+02:00  INFO 3036543 --- [test-bug] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 5 ms. Found 0 JPA repository interfaces.
Main yaml : toto
Profile yaml : my-url
2025-08-15T10:49:31.500+02:00  WARN 3036543 --- [test-bug] [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Failed to initialize dependency 'dataSourceScriptDatabaseInitializer' of LoadTimeWeaverAware bean 'entityManagerFactory': Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0: Error creating bean with name 'dataSource' defined in class path resource [fr/maif/test/bug/config/BugConfiguration.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: URL must start with 'jdbc'
2025-08-15T10:49:31.507+02:00 ERROR 3036543 --- [test-bug] [           main] o.s.boot.SpringApplication               : Application run failed

File application-bug.yaml is in $CONF directory but I don't think it's a problem, application.yaml in jar file is also not load.

application-bug.yaml

Comment From: Maths37

If it's can help you, I test some others versions on Intellij :

  • 3.4.7 : OK
  • 3.4.8 : KO
  • 3.5.0 : OK
  • 3.5.1 : OK
  • 3.5.2 : KO
$ java -cp "C:/workspaces/test-bug/target/test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar;C:/DevJava/datain"  fr.maif.test.bug.BugApplication
Picked up JAVA_TOOL_OPTIONS: -agentpath:"C:\WINDOWS\system32\Aternity\Java\JavaHookLoader.dll"="C:\ProgramData\Aternity\hooks"

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.7)

2025-08-15T12:22:48.484+02:00  INFO 23132 --- [           main] fr.maif.test.bug.BugApplication          : Starting BugApplication using Java 21.0.2 with PID 23132 (C:\workspaces\test-bug\target\test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar started by 97211P in C:\workspaces\test-bug)
2025-08-15T12:22:48.488+02:00  INFO 23132 --- [           main] fr.maif.test.bug.BugApplication          : The following 1 profile is active: "bug"
2025-08-15T12:22:49.372+02:00  INFO 23132 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2025-08-15T12:22:49.402+02:00  INFO 23132 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16 ms. Found 0 JPA repository interfaces.
Active profile : null
Profiles : [default]
Main yaml : toto
Profile yaml : my-url

$ java -cp "C:/workspaces/test-bug/target/test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar;C:/DevJava/datain"  fr.maif.test.bug.BugApplication
Picked up JAVA_TOOL_OPTIONS: -agentpath:"C:\WINDOWS\system32\Aternity\Java\JavaHookLoader.dll"="C:\ProgramData\Aternity\hooks"

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.7)

2025-08-15T12:23:38.093+02:00  INFO 21260 --- [           main] fr.maif.test.bug.BugApplication          : Starting BugApplication using Java 21.0.2 with PID 21260 (C:\workspaces\test-bug\target\test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar started by 97211P in C:\workspaces\test-bug)
2025-08-15T12:23:38.097+02:00  INFO 21260 --- [           main] fr.maif.test.bug.BugApplication          : The following 1 profile is active: "bug"
2025-08-15T12:23:39.003+02:00  INFO 21260 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2025-08-15T12:23:39.056+02:00  INFO 21260 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 32 ms. Found 0 JPA repository interfaces.
Active profile : bug
Profiles : [default]
Main yaml : toto
Profile yaml : my-url

$ java -cp "C:/workspaces/test-bug/target/test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar;C:/DevJava/datain"  fr.maif.test.bug.BugApplication
Picked up JAVA_TOOL_OPTIONS: -agentpath:"C:\WINDOWS\system32\Aternity\Java\JavaHookLoader.dll"="C:\ProgramData\Aternity\hooks"

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.8)

12:24:26.075 [main] INFO fr.maif.test.bug.BugApplication -- Starting BugApplication using Java 21.0.2 with PID 2776 (C:\workspaces\test-bug\target\test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar started by 97211P in C:\workspaces\test-bug)
12:24:26.082 [main] INFO fr.maif.test.bug.BugApplication -- No active profile set, falling back to 1 default profile: "default"
12:24:26.820 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate -- Bootstrapping Spring Data JPA repositories in DEFAULT mode.
12:24:26.850 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate -- Finished Spring Data repository scanning in 16 ms. Found 0 JPA repository interfaces.
Active profile : bug
Profiles : [default]
Main yaml : null
Profile yaml : null

$ java -cp "C:/workspaces/test-bug/target/test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar;C:/DevJava/datain"  fr.maif.test.bug.BugApplication
Picked up JAVA_TOOL_OPTIONS: -agentpath:"C:\WINDOWS\system32\Aternity\Java\JavaHookLoader.dll"="C:\ProgramData\Aternity\hooks"

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.5.0)

2025-08-15T12:25:14.170+02:00  INFO 14896 --- [           main] fr.maif.test.bug.BugApplication          : Starting BugApplication using Java 21.0.2 with PID 14896 (C:\workspaces\test-bug\target\test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar started by 97211P in C:\workspaces\test-bug)
2025-08-15T12:25:14.174+02:00  INFO 14896 --- [           main] fr.maif.test.bug.BugApplication          : The following 1 profile is active: "bug"
2025-08-15T12:25:15.042+02:00  INFO 14896 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2025-08-15T12:25:15.075+02:00  INFO 14896 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 18 ms. Found 0 JPA repository interfaces.
Active profile : bug
Profiles : [default]
Main yaml : toto
Profile yaml : my-url

$ java -cp "C:/workspaces/test-bug/target/test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar;C:/DevJava/datain"  fr.maif.test.bug.BugApplication
Picked up JAVA_TOOL_OPTIONS: -agentpath:"C:\WINDOWS\system32\Aternity\Java\JavaHookLoader.dll"="C:\ProgramData\Aternity\hooks"

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.5.2)

12:25:55.262 [main] INFO fr.maif.test.bug.BugApplication -- Starting BugApplication using Java 21.0.2 with PID 10156 (C:\workspaces\test-bug\target\test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar started by 97211P in C:\workspaces\test-bug)
12:25:55.266 [main] INFO fr.maif.test.bug.BugApplication -- No active profile set, falling back to 1 default profile: "default"
12:25:55.991 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate -- Bootstrapping Spring Data JPA repositories in DEFAULT mode.
12:25:56.029 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate -- Finished Spring Data repository scanning in 27 ms. Found 0 JPA repository interfaces.
Active profile : bug
Profiles : [default]
Main yaml : null
Profile yaml : null

$ java -cp "C:/workspaces/test-bug/target/test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar;C:/DevJava/datain"  fr.maif.test.bug.BugApplication
Picked up JAVA_TOOL_OPTIONS: -agentpath:"C:\WINDOWS\system32\Aternity\Java\JavaHookLoader.dll"="C:\ProgramData\Aternity\hooks"

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.5.1)

2025-08-15T12:26:55.143+02:00  INFO 7352 --- [           main] fr.maif.test.bug.BugApplication          : Starting BugApplication using Java 21.0.2 with PID 7352 (C:\workspaces\test-bug\target\test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar started by 97211P in C:\workspaces\test-bug)
2025-08-15T12:26:55.147+02:00  INFO 7352 --- [           main] fr.maif.test.bug.BugApplication          : The following 1 profile is active: "bug"
2025-08-15T12:26:56.079+02:00  INFO 7352 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2025-08-15T12:26:56.115+02:00  INFO 7352 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 19 ms. Found 0 JPA repository interfaces.
Active profile : bug
Profiles : [default]
Main yaml : toto
Profile yaml : my-url

Comment From: nosan

Thanks for sharing the sample - that helps a lot! Based on the provided example, it seems there is an issue with the maven-assembly-plugin, which does not correctly merge the META-INF/spring.factories files. This leads to unpredictable behavior when the application starts. For example, the JAR built with version 3.4.8 is missing many classes in META-INF/spring.factories that are present in the JAR built with 3.4.7.

I also verified all 3.4.x versions, and they all have the same issue with merging META-INF/spring.factories files.

I've created a small application that demonstrates the issue, and you can reproduce it 100% of the time. gh-46843.zip

  • Download the ZIP file.
  • Unzip it.
  • ./mvnw clean package && java -cp target/gh-issue-46843-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.example.ghissue46843.GhIssue46843Application

Different Spring Boot versions will produce different results.

Inside the ZIP file you can find the output for each Spring Boot version.

Comment From: nosan

If you build your application with Maven, and then unzip jar (jar xf target/test-bug-0.0.1-SNAPSHOT-jar-with-dependencies.jar) and check META-INF/spring.factories file, you will see the following content:

3.4.8

# ApplicationContext Initializers
org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer,\
org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener
# Application Listeners
org.springframework.context.ApplicationListener=\
org.springframework.boot.autoconfigure.BackgroundPreinitializer
# Environment Post Processors
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.boot.autoconfigure.integration.IntegrationPropertiesEnvironmentPostProcessor
# Auto Configuration Import Listeners
org.springframework.boot.autoconfigure.AutoConfigurationImportListener=\
org.springframework.boot.autoconfigure.condition.ConditionEvaluationReportAutoConfigurationImportListener
# Auto Configuration Import Filters
org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\
org.springframework.boot.autoconfigure.condition.OnBeanCondition,\
org.springframework.boot.autoconfigure.condition.OnClassCondition,\
org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition
# Failure Analyzers
org.springframework.boot.diagnostics.FailureAnalyzer=\
org.springframework.boot.autoconfigure.data.redis.RedisUrlSyntaxFailureAnalyzer,\
org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer,\
org.springframework.boot.autoconfigure.jdbc.DataSourceBeanCreationFailureAnalyzer,\
org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer,\
org.springframework.boot.autoconfigure.jooq.NoDslContextBeanFailureAnalyzer,\
org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryBeanCreationFailureAnalyzer,\
org.springframework.boot.autoconfigure.r2dbc.MissingR2dbcPoolDependencyFailureAnalyzer,\
org.springframework.boot.autoconfigure.r2dbc.MultipleConnectionPoolConfigurationsFailureAnalyzer,\
org.springframework.boot.autoconfigure.r2dbc.NoConnectionFactoryBeanFailureAnalyzer,\
org.springframework.boot.autoconfigure.ssl.BundleContentNotWatchableFailureAnalyzer
# Template Availability Providers
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\
org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.mustache.MustacheTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.web.servlet.JspTemplateAvailabilityProvider
# DataSource Initializer Detectors
org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector=\
org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializerDatabaseInitializerDetector
# Depends on Database Initialization Detectors
org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector=\
org.springframework.boot.autoconfigure.batch.JobRepositoryDependsOnDatabaseInitializationDetector,\
org.springframework.boot.autoconfigure.quartz.SchedulerDependsOnDatabaseInitializationDetector,\
org.springframework.boot.autoconfigure.session.JdbcIndexedSessionRepositoryDependsOnDatabaseInitializationDetector

And this is for 3.4.7


# Logging Systems
org.springframework.boot.logging.LoggingSystemFactory=\
org.springframework.boot.logging.java.JavaLoggingSystem$Factory,\
org.springframework.boot.logging.log4j2.Log4J2LoggingSystem$Factory,\
org.springframework.boot.logging.logback.LogbackLoggingSystem$Factory
# PropertySource Loaders
org.springframework.boot.env.PropertySourceLoader=\
org.springframework.boot.env.PropertiesPropertySourceLoader,\
org.springframework.boot.env.YamlPropertySourceLoader
# ConfigData Location Resolvers
org.springframework.boot.context.config.ConfigDataLocationResolver=\
org.springframework.boot.context.config.ConfigTreeConfigDataLocationResolver,\
org.springframework.boot.context.config.StandardConfigDataLocationResolver
# ConfigData Loaders
org.springframework.boot.context.config.ConfigDataLoader=\
org.springframework.boot.context.config.ConfigTreeConfigDataLoader,\
org.springframework.boot.context.config.StandardConfigDataLoader
# Application Context Factories
org.springframework.boot.ApplicationContextFactory=\
org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContextFactory,\
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContextFactory
# Run Listeners
org.springframework.boot.SpringApplicationRunListener=\
org.springframework.boot.context.event.EventPublishingRunListener
# Error Reporters
org.springframework.boot.SpringBootExceptionReporter=\
org.springframework.boot.diagnostics.FailureAnalyzers
# Application Context Initializers
org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\
org.springframework.boot.context.ContextIdApplicationContextInitializer,\
org.springframework.boot.io.ProtocolResolverApplicationContextInitializer,\
org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer,\
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
# Application Listeners
org.springframework.context.ApplicationListener=\
org.springframework.boot.ClearCachesApplicationListener,\
org.springframework.boot.builder.ParentContextCloserApplicationListener,\
org.springframework.boot.context.FileEncodingApplicationListener,\
org.springframework.boot.context.config.AnsiOutputApplicationListener,\
org.springframework.boot.context.logging.LoggingApplicationListener,\
org.springframework.boot.env.EnvironmentPostProcessorApplicationListener
# Environment Post Processors
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor,\
org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor,\
org.springframework.boot.env.RandomValuePropertySourceEnvironmentPostProcessor,\
org.springframework.boot.env.SpringApplicationJsonEnvironmentPostProcessor,\
org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor,\
org.springframework.boot.reactor.ReactorEnvironmentPostProcessor
# Failure Analyzers
org.springframework.boot.diagnostics.FailureAnalyzer=\
org.springframework.boot.context.config.ConfigDataNotFoundFailureAnalyzer,\
org.springframework.boot.context.properties.IncompatibleConfigurationFailureAnalyzer,\
org.springframework.boot.context.properties.NotConstructorBoundInjectionFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.AotInitializerNotFoundFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.BeanCurrentlyInCreationFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.BeanDefinitionOverrideFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.BeanNotOfRequiredTypeFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.BindFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.BindValidationFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyNameFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyValueFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.MissingParameterNamesFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.MutuallyExclusiveConfigurationPropertiesFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.NoSuchMethodFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.NoUniqueBeanDefinitionFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.PatternParseFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.PortInUseFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.UnboundConfigurationPropertyFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer,\
org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer,\
org.springframework.boot.web.context.MissingWebServerFactoryBeanFailureAnalyzer,\
org.springframework.boot.web.embedded.tomcat.ConnectorStartFailureAnalyzer
# Failure Analysis Reporters
org.springframework.boot.diagnostics.FailureAnalysisReporter=\
org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter
# Database Initializer Detectors
org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector=\
org.springframework.boot.flyway.FlywayDatabaseInitializerDetector,\
org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializerDetector,\
org.springframework.boot.liquibase.LiquibaseDatabaseInitializerDetector,\
org.springframework.boot.orm.jpa.JpaDatabaseInitializerDetector,\
org.springframework.boot.r2dbc.init.R2dbcScriptDatabaseInitializerDetector
# Depends On Database Initialization Detectors
org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector=\
org.springframework.boot.jdbc.SpringJdbcDependsOnDatabaseInitializationDetector,\
org.springframework.boot.jooq.JooqDependsOnDatabaseInitializationDetector,\
org.springframework.boot.orm.jpa.JpaDependsOnDatabaseInitializationDetector,\
org.springframework.boot.sql.init.dependency.AnnotationDependsOnDatabaseInitializationDetector
# Resource Locator Protocol Resolvers
org.springframework.core.io.ProtocolResolver=\
org.springframework.boot.io.Base64ProtocolResolver
# Resource File Path Resolvers
org.springframework.boot.io.ApplicationResourceLoader$FilePathResolver=\
org.springframework.boot.io.ClassPathResourceFilePathResolver,\
org.springframework.boot.web.reactive.context.FilteredReactiveWebContextResourceFilePathResolver,\
org.springframework.boot.web.servlet.context.ServletContextResourceFilePathResolver

As you can see, the META-INF/spring.factories file contains a list of factory classes that are used by Spring Boot to configure various aspects of the application context, environment, and other components. One of these classes is EnvironmentPostProcessorApplicationListener, which is responsible for processing environment post-processors. Since it is absent in the META-INF/spring.factories file in version 3.4.8, the application files are not processed, which causes the issue.

Comment From: philwebb

Thanks @nosan!

I think the problem here is that you're not using the shade plugin, you're getting a JAR with this spring.factories content.

Comment From: philwebb

Replacing the assembly plugin with the shade plugin appears to fix the issue:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Comment From: Maths37

Replacing the assembly plugin with the shade plugin appears to fix the issue:

org.apache.maven.plugins maven-shade-plugin package shade

Thank you for your solution, I test it on my project and it's works fine :).

@nosan Thank you for your analyze !

Nb : It's a real bug with maven assembly plugin or it's discourage to use it with spring boot ?

Comment From: philwebb

It's not a bug IMO. The assembly plugin is a general purpose tool and it doesn't have any specific knowledge of Spring Boot. The reason that shade works is it supports the concept of resource transformers, and we provide and configure one for spring.factories.