My application is not starting, because of missing application properties.

In the source of the application I have default properties:

$ ls dmz/src/main/resources         
application-local.yml
application.yml

Dockerfile

FROM ubi9-minimal-java21:latest

USER 1001

WORKDIR /app

ARG EXTRACTED=./extracted
COPY ${EXTRACTED}/dependencies/ ./
COPY ${EXTRACTED}/spring-boot-loader/ ./
COPY ${EXTRACTED}/snapshot-dependencies/ ./
COPY ${EXTRACTED}/application/ ./

EXPOSE 8080

CMD java $JAVA_OPTS $JAVA_OPTS_EXT org.springframework.boot.loader.launch.JarLauncher

When starting the container I mount specific application properties in the app folder in the Docker container:

$ podman run --rm -it -v ~/infra/x/application-specific.yml:/app/application.yml localhost/bingo
2024-01-12T14:30:41.382Z ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webClientConfig' defined in URL [jar:file:/app/BOOT-INF/lib/shared-adapter-0.8.0-SNAPSHOT-plain.jar!/com/x/shared/adapter/WebClientConfig.class]: Unexpected exception during bean creation
...
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'x.consumer-id' in value "${x.consumer-id}"

x.consumer-id is defined in the classpath application properties (not in the application-specific).

When I dump all properties on startup, I see, that only properties from application-specific.yml are present

====== Log all properties for testing ======
Active profiles: [entw]
java.specification.version: 21
...
PWD: /app
_: /usr/bin/java
HOSTNAME: 239bb637b5cf
spring.profiles.active: stage <--- from `application-specific.yml`
...

Comment From: wilkinsona

I'm finding the steps a little hard to follow, but I believe you've got application.yml on the classpath in two places:

  • /app/application.yml
  • /app/BOOT-INF/classes/application.yml

When the same thing appears in multiple places on the classpath, one of them will win and any others will be ignored. I suspect that's what's happening here.

If I've misunderstood and you don't think this is the case, please provide a minimal example and we can take another look. Such an example would, ideally, not involve Docker as I suspect it isn't part of the problem.

Comment From: mavarazo

You are right. This worked before I switched to extracted application. Probably because the classpath and external can have the same file name.

I managed to get it working by adding the specific application properties with a different name and with an env SPRING_CONFIG_ADDITIONAL_LOCATION pointing to the file.

Comment From: wilkinsona

Great. Thanks for letting us know.