我尝试使用docker image启动我的应用程序(Spring Boot + Spring Cloud + Eureka + MongoDB),但我无法连接到MongoDB.
例外:
exception "com.mongodb.MongoSocketOpenException: Exception opening socket."
Run Code Online (Sandbox Code Playgroud)
我用execute命令启动我的应用程序:docker-compose up --build
Docker日志:
application.yml:
# Spring properties
spring:
application:
name: car-service
data:
mongodb.host: localhost
mongodb.port: 32769
mongodb.uri: mongodb://localhost/test
mongo.repositories.enabled: true
# Discovery Server Access
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
# HTTP Server (Tomcat) Port
server:
port: 2220
error:
whitelabel:
enabled: false
Run Code Online (Sandbox Code Playgroud)
泊坞窗,compose.yml:
eureka:
build: ./eureka-discovery-service
ports:
- "8761:8761"
mongodb:
image: mongo:3.0.4
ports:
- "32769:32769"
postgresql:
image: postgres:9.6.1
ports:
- "32770:32770"
gateway-service:
build: …
Run Code Online (Sandbox Code Playgroud) 我想在数据库中添加订单。我的订单包括:user_id、flight_id、姓名、电话、邮件。
命令:
@Entity
@Table(name = "order")
public class Order extends BaseEntity {
private User user;
private Flight flight;
private String name;
private String surname;
private String phone;
private String mail;
public Order() {
super();
}
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@ManyToOne
@JoinColumn(name = "flight_id", nullable = false)
public Flight getFlight() {
return flight;
}
public void setFlight(Flight flight) {
this.flight = flight; …
Run Code Online (Sandbox Code Playgroud)