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;
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!
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()