【发布时间】:2020-01-14 16:23:11
【问题描述】:
我正在尝试在 Docker 上部署 Spring Server。 Spring 服务器正在连接到在另一个应用程序中运行的 RabbitMQ 服务器。连接到 rabbitmq 时出现错误。我在 application.properties 中添加了主机,但没有用。比作为环境变量添加到应用程序容器中并且仍然不起作用。我还重建了 jar 并更改了图像版本。
version: '3'
services:
rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672" #JMS Port
- "15672:15672" #Management Port - default user:pass = guest:guest
db:
image: mysql:5.7.22
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "hospital"
MYSQL_PASSWORD: "root"
ports:
- "3306:3306"
networks:
- mysql_bridge
restart: always
springboot-docker-compose-app-container:
image: app-image
build:
context: ./
dockerfile: Dockerfile
environment: # Pass environment variables to the service
SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/hospital?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false&allowPublicKeyRetrieval=true
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root
SPRING_RABBITMQ_HOST: rabbitmq
depends_on:
- rabbitmq
- db
volumes:
- /data/VerzorgerSOAP
ports:
- "8080:8080"
networks:
- mysql_bridge
- rabbiy_mq
networks:
mysql_bridge:
rabbiy_mq:
这也是我的 application.properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.generate-ddl=true
spring.datasource.url = jdbc:mysql://db:3306/hospital?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false&allowPublicKeyRetrieval=true
spring.jpa.hibernate.ddl-auto = update
spring.datasource.username = root
spring.datasource.password = root
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false
server.ssl.enabled=false
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.rabbitmq.host= rabbitmq
这是我得到的错误
org.springframework.amqp.AmqpIOException: java.net.UnknownHostException: rabbitmq
【问题讨论】:
-
RabbitMQ 未连接到 rabbiy_mq。只需将网络添加到 RabbitMQ 的配置中
-
您也可以删除文件中的所有
networks:,让所有内容都在自动创建的default网络上。 -
非常感谢,我编辑和工作,但知道我得到
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused -
@Siespi123 你解决问题了吗?
-
好的,谢谢大家。
标签: spring spring-boot docker rabbitmq