我有一个基于java spring的微服务环境,使用docker compose部署在docker容器上。微服务允许call A从spring配置服务器读取属性和配置。设置在本地成功工作,但在docker中抛出FileNotFound错误。
我正在使用**@PropertySource**阅读文件
微服务A:
@Component
@PropertySource(value = "file:../configurations/src/main/resources/properties/common/event-mapping.yml")
@ConfigurationProperties(prefix = "api")
public class EventMapping {...}
Docker编写:
version: "3.9"
services:
configurationsService:
image: "configurations-service"
hostname: configurationsService
ports:
- "9080:9080"
environment:
JAVA_OPTS:
"-Dspring.profiles.active=native,dev"
healthcheck:
test: "curl --fail --silent configurationsService:9080/actuator/health | grep UP || exit 1"
interval: 20s
timeout: 5s
retries: 5
start_period: 40s
microserviceA:
image: "microservice-A"
ports:
- "8080:8080"
depends_on:
configurationsService:
condition: service_healthy
restart: true
environment:
JAVA_OPTS:
"-Dspring.profiles.active=dev"
日志
microserviceA-1 | Caused by: java.lang.IllegalStateException: java.io.FileNotFoundException: ../configurations/src/main/resources/properties/common/event-mapping.yml (No such file or directory)
microserviceA-1 | at org.springframework.beans.factory.config.YamlProcessor.handleProcessError(YamlProcessor.java:222)
microserviceA-1 | at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:214)
microserviceA-1 | at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:166)
microserviceA-1 | at org.springframework.beans.factory.config.YamlPropertiesFactoryBean.createProperties(YamlPropertiesFactoryBean.java:135)
microserviceA-1 | at org.springframework.beans.factory.config.YamlPropertiesFactoryBean.getObject(YamlPropertiesFactoryBean.java:115)
microserviceA-1 | at com.openreach.inams.createalarm.config.YamlPropertySourceFactory.createPropertySource(YamlPropertySourceFactory.java:21)
microserviceA-1 | at org.springframework.core.io.support.PropertySourceProcessor.processPropertySource(PropertySourceProcessor.java:87)
microserviceA-1 | at org.springframework.context.annotation.PropertySourceRegistry.processPropertySource(PropertySourceRegistry.java:77)
1条答案
按热度按时间kt06eoxx1#
嘿
您可以通过在容器之间使用共享卷来解决问题。
https://docs.docker.com/storage/volumes/