【发布时间】:2020-11-01 07:13:04
【问题描述】:
我有 2 个 spring 微服务应用程序并希望它们访问同一个数据库。但是当我运行它们时,这两个应用程序都会创建不同的数据库。 Application.yml 文件:
服务 1:
server.port: 8002
logging:
level:
org:
springframework:
jdbc:
core:
DEBUG
spring:
application:
name: movie
datasource:
url: jdbc:h2:mem:movie_service
driver-class-name: org.h2.Driver
h2:
console:
enabled: true
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8001/eureka}
registryFetchIntervalSeconds: 1
instance:
leaseRenewalIntervalInSeconds: 1
#preferIpAddress: true
eureka.instance.prefer-ip-address: false
服务 2:
server.port: 8003
spring:
application.name: client
datasource:
url: jdbc:h2:mem:movie_service
driver-class-name: org.h2.Driver
h2:
console:
enabled: true
logging:
level:
org:
springframework:
jdbc:
core:
DEBUG
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8001/eureka}
registryFetchIntervalSeconds: 1
instance:
leaseRenewalIntervalInSeconds: 1
#preferIpAddress: true
eureka.instance.prefer-ip-address: false
我认为通过提供相同的 URL,一个服务将创建数据库,而另一个将只使用它。
【问题讨论】:
-
不建议在微服务之间共享数据库。看到这个帖子:stackoverflow.com/questions/43612866/…
标签: java spring spring-boot netflix-eureka in-memory-database