How to use external configuration properties in a spring boot app running on a docker windows image as layered jar?

Viewed 27

Every time when I start my container with my spring boot app I get a FileNotFound exception for my properties:

2022-09-06 13:03:15.746  INFO 1412 --- [           main] c.m.cdmf.svms.SVMSControllerApplication  : Starting SVMSControllerApplication v3.3.2-SNAPSHOT using Java 1.8.0_212 on 9aff754dd15d with PID 1412 (C:\application\BOOT-INF\classes started by ContainerAdministrator in C:\application)
2022-09-06T12:03:15.767885300Z 2022-09-06 13:03:15.746  INFO 1412 --- [           main] c.m.cdmf.svms.SVMSControllerApplication  : No active profile set, falling back to 1 default profile: "default"
2022-09-06T12:03:15.872396900Z 2022-09-06 13:03:15.855  WARN 1412 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.mottmac.cdmf.svms.SVMSControllerApplication]; nested exception is java.io.FileNotFoundException: class path resource [SVMSController.properties] cannot be opened because it does not exist
2022-09-06T12:03:15.911392600Z 2022-09-06 13:03:15.887 ERROR 1412 --- [           main] o.s.boot.SpringApplication               : Application run failed
2022-09-06T12:03:15.911392600Z 
2022-09-06T12:03:15.911392600Z org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.mottmac.cdmf.svms.SVMSControllerApplication]; nested exception is java.io.FileNotFoundException: class path resource [SVMSController.properties] cannot be opened because it does not exist

My Dockerfile:

FROM my.private.repo:5000/windows-java/8-jdk-windowsnanoserver-10.0.14393.1066:latest as builder
WORKDIR application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN powershell java -Djarmode=layertools -jar application.jar extract

FROM my.private.repo:5000/windows-java/8-jdk-windowsnanoserver-10.0.14393.1066:latest
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
EXPOSE 8080
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher", "--spring.config.location=file:///C:/application/BOOT-INF/classes/config/SVMSController.properties"]

As you can see C:/application/BOOT-INF/classes/config/SVMSController.properties is a mounted volume inside my container which is referencing the location on my host where the properties are (C:\my-app-props) when I run my docker container. I can confirm the folder is not empty on the container as I checked if the files are visible and they are.

My Application with the main method where configuration happens:

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
@PropertySource("classpath:SVMSController.properties")
public class SVMSControllerApplication implements ApplicationRunner
{
    public static void main(String[] args)
    {
        SpringApplication.run(SVMSControllerApplication.class);
    }
}
0 Answers
Related