用mysql数据库上传到circleci时出错-maven clean在maven测试之前运行时也会产生问题

xeufq47z  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(168)

我在intellij中使用hibernate框架和maven。我正在创建一个mysql数据库,我还有一些Mapmysql数据库的orm类,然后我运行一些junit测试来确保一切正常。
我遇到麻烦的地方有两个,它们相互关联:
当我跑的时候 mvn test ,有时我的junit测试工作得很好,能够查询模拟数据库、建立连接(即使只是与模拟数据库连接)、执行语句等 mvn clean 跑步前 mvn test ,当junit测试仍然执行时,测试输出失败(当然不是错误,只是失败,尽管这仍然很糟糕)。
当我上传到github并运行circleci时,#1中概述的问题实际上是重复的(这并不奇怪,因为circleci运行 mvn test 进行集成测试时)。我的大部分上传都失败了,但其中一个终于成功了。然而,我不太清楚为什么“最终”上传成功而其他人没有。
我收到的错误消息 mvn test 或者circleci构建通常如下所示。这些错误来自于我的pent ultimate上传,我在下一次上传之前做的那次上传实际上起了作用:

java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

com.mysql.cj.exceptions.CJException: Public Key Retrieval is not allowed

java.sql.SQLNonTransientConnectionException: Could not create connection to database server

我还应该指出,我的意图是参选 mvn clean 先上传到circleci,然后运行 mvn clean 似乎在某种程度上参与了这些错误的延续。
就我使用的不同资源而言,它们就在这里。如果我忘记了什么,请让我知道,我应该能够包括它。
在hibernate.cfg.xml文件中,我有以下几行:

<property name="connection.url">jdbc:mysql://localhost:3306/stocks</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

在第一行“股票”一词的末尾,我有时会添加以下内容(有时我只添加以下内容之一,有时我会将它们合并,具体取决于maven或circleci的错误)。附加这些行的一些组合似乎有助于使事情正常进行,但是 mvn clean 似乎阻止了这些添加所产生的任何影响:

autoReconnect=true
useSSL=false
allowPublicKeyRetrieval=true

在intellij中运行junit测试通常是可行的,但是如果我运行 mvn clean 首先,intellij通常不起作用,除非我回到这个文件并附加 ?autoReconnect=true&amp;useSSL=false . 如果我这样做,那么intellij将很好地运行junit测试。
在circleci的config.yml文件中,我有以下代码。基于我所做的其他研究,mavenèopts中添加了某些语句,试图抵消我所犯的错误,但我不知道这些语句是否有任何影响:


# Java Maven CircleCI 2.0 configuration file

# 

# Check https://circleci.com/docs/2.0/language-java/ for more details

# 

version: 2
jobs:
  build:
    docker:
    # specify the version you desire here
    - image: circleci/openjdk:8-jdk

    # Specify service dependencies here if necessary
    # CircleCI maintains a library of pre-built images
    # documented at https://circleci.com/docs/2.0/circleci-images/
    # - image: circleci/postgres:9.4
    - image: circleci/mysql:latest-ram
      environment:
      - MYSQL_ROOT_PASSWORD: (my real password goes here)
      - MYSQL_DATABASE: stocks
      - MYSQL_USER: bob
      - MYSQL_PASSWORD: (the real password goes here)

    working_directory: ~/repo

    environment:
      # Customize the JVM maximum heap limit
      MAVEN_OPTS: -Xmx3200m -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true

    steps:
    - checkout
    - run: sudo apt install -y mysql-client

    # Download and cache dependencies
    - restore_cache:
        keys:
        - v1-dependencies-{{ checksum "pom.xml" }}
        # fallback to using the latest cache if no exact match is found
        - v1-dependencies-

    - run: mvn dependency:go-offline

    - save_cache:
        paths:
        - ~/.m2
        key: v1-dependencies-{{ checksum "pom.xml" }}

    # run tests!
    - run: mvn integration-test

如果有人知道发生了什么事,我很感激你的帮助。我的目标是能够上传到circleci的第一次运行 mvn clean 所以只有 src 文件夹, pom.xml 文件,以及 .circleci 文件夹包含在上载中。另外,不是说belabor的观点,但是我最近上传到circleci的东西确实有用,但是我不确定是什么让这个构建工作,而其他的构建工作都没有。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题