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
.