通信链接失败。Spring启动,MySQL,Docker

问题描述 投票:0回答:1

我有一个微服务架构,每个微服务都有自己的mysql数据库。该应用程序在IDE中运行良好,但我在部署时遇到了问题,因为我无法将我的mysql数据库绑定到游戏微服务。我得到的是通信链接失败。堆栈跟踪如下。

docker-compose.yml

version: '3'
services:
  # Database
  game-mysql-db:
    image: mysql:5.7
    container_name: game-mysql-db
    hostname: mysql-game
    restart: always
    environment:
      MYSQL_DATABASE: 'boardify_game_development'
      MYSQL_USER: 'Boardify'
      MYSQL_PASSWORD: 'boardify'
      MYSQL_ROOT_PASSWORD: 'password'
    ports:
      - "3306:3306"
    expose:
      - "3306"
    networks:
      - boardify-app-network

  # Core services
  service-discovery:
    hostname: service-discovery
    image: eureka-server
    container_name: service-discovery
    restart: always
    ports:
      - "8761:8761"
    networks:
      - boardify-app-network


  boardify-game-service:
    build:
      context: ./game
      args:
        JAR_FILE: game-0.0.1-SNAPSHOT.jar
      dockerfile: Dockerfile
    image: game
    container_name: boardify-game-service
    hostname: boardify-game-service
    ports:
      - "8083:8083"
    networks:
      - boardify-app-network
    environment:
      - SERVER_PORT=8083
      - EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://service-discovery:8761/eureka
      - SPRING_PROFILES_ACTIVE=production
      - SPRING_DATASOURCE_URL:jdbc:mysql://game-mysql-db:3306/boardify_game_development
    depends_on:
      - game-mysql-db

networks:
  boardify-app-network:
    driver: bridge

应用-生产.属性

#tomcat properties
server.port=8083
#logging file properties
logging.file.path=./logs
logging.file.name=${logging.file.path}/game.log
#application properties
spring.application.name=game-service
#liquibase properties
#database properties
[email protected]@
[email protected]@
[email protected]@
[email protected]@
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
#jpa properties
# Show or not log for each sql query
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
[email protected]@

eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.registry-fetch-interval-seconds=30

eureka.instance.prefer-ip-address=true
eureka.instance.lease-renewal-interval-in-seconds=30
eureka.instance.lease-expiration-duration-in-seconds=60
security.jwt.url=/authenticate/login
security.jwt.header=Authorization
security.jwt.header.prefix=Bearer
security.jwt.expiration=1800000
security.jwt.secret=securitysecret23992_2332

eureka.client.service-url.defaultZone = http://service-discovery:8761/eureka

设置.xml

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <profiles>
        <profile>
            <id>production</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>prod</value>
                </property>
            </activation>
            <properties>
                <game.db.url>jdbc:mysql://game-mysql-db:3306/boardify_game_development</game.db.url>
                <db.driverClassName>com.mysql.jdbc.Driver</db.driverClassName>
                <sql.dialect>org.hibernate.dialect.MySQL5Dialect</sql.dialect>              
            </properties>
        </profile>

    </profiles>

</settings>

堆栈跟踪。

boardify-game-service    | 2020-05-17 08:19:40.932  WARN 1 --- [           main] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct ins
tantiation.
boardify-game-service    | 2020-05-17 08:19:42.164 ERROR 1 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.
boardify-game-service    |
boardify-game-service    | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
boardify-game-service    |
boardify-game-service    | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
boardify-game-service    |      at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:353) ~[HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201) ~[HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473) [HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562) [HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) [HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) [HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.HikariDataSource$$FastClassBySpringCGLIB$$eeb1ae86.invoke(<generated>) [HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) [spring-core-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:769) [spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747) [spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136) [spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) [spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747) [spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) [spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at com.zaxxer.hikari.HikariDataSource$$EnhancerBySpringCGLIB$$20e93c44.getConnection(<generated>) [HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:311) [liquibase-core-3.8.0.jar!/:na]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862) [spring-beans-5.2.0.RELEASE.jar!/:5.2.0.R
ELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799) [spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELE
ASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) [spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE
]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) [spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) [spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) [spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) [spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) [spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) [spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108) ~[spring-context-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.2.0.RELEASE.jar!/:5.2.0.RELEASE
]
boardify-game-service    |      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at boardify.game.GameApplication.main(GameApplication.java:12) ~[classes!/:0.0.1-SNAPSHOT]
boardify-game-service    |      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
boardify-game-service    |      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
boardify-game-service    |      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
boardify-game-service    |      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
boardify-game-service    |      at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[game.jar:0.0.1-SNAPSHOT]
boardify-game-service    |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[game.jar:0.0.1-SNAPSHOT]
boardify-game-service    |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) ~[game.jar:0.0.1-SNAPSHOT]
boardify-game-service    |      at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) ~[game.jar:0.0.1-SNAPSHOT]
boardify-game-service    | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
boardify-game-service    |
boardify-game-service    | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
boardify-game-service    |      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_212]
boardify-game-service    |      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_212]
boardify-game-service    |      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_212]
boardify-game-service    |      at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_212]
boardify-game-service    |      at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.NativeSession.connect(NativeSession.java:144) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      ... 50 common frames omitted
boardify-game-service    | Caused by: java.net.ConnectException: Connection refused (Connection refused)
boardify-game-service    |      at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_212]
boardify-game-service    |      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_212]
boardify-game-service    |      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_212]
boardify-game-service    |      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_212]
boardify-game-service    |      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_212]
boardify-game-service    |      at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_212]
boardify-game-service    |      at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      ... 53 common frames omitted
boardify-game-service    |
boardify-game-service    | 2020-05-17 08:19:42.186  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springf
ramework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguratio
n.class]: Invocation of init method failed; nested exception is liquibase.exception.DatabaseException: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
boardify-game-service    |
boardify-game-service    | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
boardify-game-service    | 2020-05-17 08:19:42.210  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
boardify-game-service    | 2020-05-17 08:19:42.429  INFO 1 --- [           main] ConditionEvaluationReportLoggingListener :
boardify-game-service    |
boardify-game-service    | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
boardify-game-service    | 2020-05-17 08:19:42.467 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed
boardify-game-service    |
boardify-game-service    | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseA
utoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.DatabaseException: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link fa
ilure
boardify-game-service    |
boardify-game-service    | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1803) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.REL
EASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEAS
E]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]

boardify-game-service    |      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108) ~[spring-context-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.2.0.RELEASE.jar!/:5.2.0.RELEASE
]
boardify-game-service    |      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
boardify-game-service    |      at boardify.game.GameApplication.main(GameApplication.java:12) [classes!/:0.0.1-SNAPSHOT]
boardify-game-service    |      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
boardify-game-service    |      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
boardify-game-service    |      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
boardify-game-service    |      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
boardify-game-service    |      at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [game.jar:0.0.1-SNAPSHOT]
boardify-game-service    |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [game.jar:0.0.1-SNAPSHOT]
boardify-game-service    |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) [game.jar:0.0.1-SNAPSHOT]
boardify-game-service    |      at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) [game.jar:0.0.1-SNAPSHOT]
boardify-game-service    | Caused by: liquibase.exception.DatabaseException: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
boardify-game-service    |
boardify-game-service    | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
boardify-game-service    |      at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:316) ~[liquibase-core-3.8.0.jar!/:na]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.
RELEASE]
boardify-game-service    |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799) ~[spring-beans-5.2.0.RELEASE.jar!/:5.2.0.REL
EASE]
boardify-game-service    |      ... 26 common frames omitted
boardify-game-service    | Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
boardify-game-service    |
boardify-game-service    | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
boardify-game-service    |      at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
boardify-game-service    |      at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:353) ~[HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201) ~[HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473) ~[HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562) ~[HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at com.zaxxer.hikari.HikariDataSource$$FastClassBySpringCGLIB$$eeb1ae86.invoke(<generated>) ~[HikariCP-3.4.1.jar!/:na]
boardify-game-service    |      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:769) ~[spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747) ~[spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136) ~[spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
boardify-game-service    |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747) ~[spring-aop-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]

boardify-game-service exited with code 1
service-discovery        | 2020-05-17 08:19
java mysql spring-boot docker microservices
1个回答
0
投票

在研究了这个问题整整一周的痛苦之后,我意外的解决了这个问题。我在游戏的环境(docker-compose)中加入了这3行代码。

  - spring.liquibase.url=jdbc:mysql://game-mysql-db:3306/boardify_game_development
  - spring.liquibase.user=Boardify
  - spring.liquibase.password=boardify

我只设置了spring_datasource_url.我是在application.properties中设置的,但看起来我必须在环境中设置。

© www.soinside.com 2019 - 2024. All rights reserved.