1

I use Jib to generate and push to DockerHub a Spring Boot image

mvn compile jib:build

The pom contain references:

<resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>application.properties</include>
                <include>languages.json</include>
            </includes>
        </resource>
    </resources>

then I pack and run with a docker-compose differentes containers

javaws:
    container_name: javaws
    image: myJavaWS:latest
    environment:
        - SPRING_PROFILES_ACTIVE=${ENV}
        - SPRING_CONFIG_LOCATION=${JAVA_WS_ENV_PROP_FILE}
    expose:
        - ${JAVA_WS_PORT}
    ports:
        - 9000:9000
    links:
        - my-db
    depends_on:
        - my-db
    volumes:
        - "/root/DOCKER/config:/config"
        - ${FS_FILE_PATH}:/root/path

in the docker-compose i set the application-.yml and the Spring active profile too to use

JAVA_WS_ENV_PROP_FILE=file:/config/application-WSTEST.yml

the .jar has got also a application.properties file; the docker image too;

project tree

info.app.description=My WS
info.app.name=My java WS
info.app.version=@project.version@

once the image is download from DockerHub, I verify inside the image with dive that the file is present!

dive screenshot

The application run fail because the attribute in the application.properties has not be resolved.

    2020-11-13 14:23:05,673 ERROR org.springframework.boot.SpringApplication : Application run failed
smrt-java-ws   | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springShopOpenAPI' defined in class path resource [ch/smartravel/config/SwaggerOASConfig.class]: Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'info.app.name' in value "${info.app.name}"
smrt-java-ws   |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:529)
smrt-java-ws   |    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
smrt-java-ws   |    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
smrt-java-ws   |    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)

the controller endpoint is:

@Configuration
public class SwaggerOASConfig {

@Bean
public OpenAPI springShopOpenAPI(
        @Value("${info.app.name}") String appName,
        @Value("${info.app.version:unknow}") String appVersion) {
    return new OpenAPI()
BNT
  • 23
  • 2
  • 6
  • This may be relevant: https://github.com/GoogleContainerTools/jib/issues/800 Assuming your issue is the same one, the Jib team was not able to reproduce it. If you can provide a small reproducible sample, it would help the Jib team investigate it. – Chanseok Oh Nov 13 '20 at 15:50
  • I already use: SPRING_CONFIG_LOCATION to set the env config properties file inside my docker-compose; it's possible to set a second resource file in another way? I can put with Jib tag inside my pom an extra file and than charge it as a resource? – BNT Nov 13 '20 at 20:27
  • I'm not really familiar with Spring Boot, but could it be that `SPRING_CONFIG_LOCATION` in the docker-compose environment is overriding the default? At least I know you can specify [multiple locations](https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-files) in `SPRING_CONFIG_LOCATION`. How about `SPRING_CONFIG_LOCATION=file:/config/application-WSTEST.yml,file:/app/resources/application.properties`? – Chanseok Oh Nov 13 '20 at 22:03
  • This workaround works fine. Thank's a lot @ChanseokOh! – BNT Nov 15 '20 at 20:34

1 Answers1

2

Based on the comments above, the root cause seems to be that your custom SPRING_CONFIG_LOCATION in the docker-compose setup overrides the default, preventing your app from looking into other locations including /app/resources/application.properties.

Chanseok Oh
  • 3,920
  • 4
  • 23
  • 63