【发布时间】:2018-02-22 01:23:25
【问题描述】:
我有一个 Spring Boot 应用程序,目前在 Heroku 的 CI 中构建和运行测试,我正试图让它在 Circle CI 中也能工作。我的配置文件如下所示:
version: 2
jobs:
build:
docker:
- image: circleci/jdk8:0.1.1
- image: postgres:9.6
working_directory: ~/repo
environment:
# Customize the JVM maximum heap limit
JVM_OPTS: -Xmx3200m
TERM: dumb
steps:
- checkout
- run: chmod +x gradlew
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.gradle" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: ./gradlew dependencies
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "build.gradle" }}
# run tests!
- run: ./gradlew test
我尝试了各种定义 DATABASE_URL 的方法都没有效果:
jobs:
build:
docker:
- image: circleci/jdk8:0.1.1
environment:
- DATABASE_URL=postgresql://dashman_test@localhost:5433/dashman_test
- image: postgres:9.6
environment:
- POSTGRES_USER=dashman_test
- POSTGRES_DB=dashman_test
jobs:
build:
docker:
- image: circleci/jdk8:0.1.1
environment:
- DATABASE_URL=postgresql://dashman_test@localhost:5434/dashman_test
- image: postgres:9.6
environment:
- POSTGRES_USER=dashman_test
- POSTGRES_DB=dashman_test
jobs:
build:
docker:
- image: circleci/jdk8:0.1.1
environment:
DATABASE_URL: postgresql://dashman_test@localhost:5434/dashman_test
- image: postgres:9.6
environment:
POSTGRES_USER: dashman_test
POSTGRES_DB: dashman_test
TEST_DATABASE_URL: postgresql://ubuntu@localhost/circle_test?sslmode=disable
DATABASE_URL: postgresql://ubuntu@localhost/circle_test?sslmode=disable
DATABASE_URL: postgres://ubuntu:@127.0.0.1:5433/circle_test
DATABASE_URL: postgres://localhost:5433/dashman_test
DATABASE_URL: postgresql://ubuntu@localhost:5434/circle_test?sslmode=disable
DATABASE_URL: postgres://dashman_test:KnDnHtzneyTzps0WuYr35r9@localhost:5433/dashman_test
似乎没有任何效果,我总是以这个错误结束:
tech.dashman.dashmanserver.models.AccountTest > create FAILED
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.BeanInstantiationException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.BeanInstantiationException
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException
tech.dashman.dashmanserver.models.UserTest > create FAILED
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.BeanInstantiationException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.BeanInstantiationException
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException
tech.dashman.dashmanserver.DashmanserverApplicationTests > contextLoads FAILED
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.BeanInstantiationException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.BeanInstantiationException
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException
配置数据库的正确方法是什么?我有点迷茫。
【问题讨论】:
-
你的 DATABASE_URL 是什么?
-
@StanislavL:我添加了我尝试过的每个 DATABASE_URL 的列表。你问的是这个吗?
-
难道 postgree 在 docker 容器中运行,所以你需要容器 IP(或名称)而不是 localhost?
-
@StanislavL:也许,我不知道,但这似乎表明并非如此:circleci.com/docs/2.0/postgres-config
-
您是否尝试过 dbl 引用
- DATABASE_URL="postgresql://dashman_test@localhost:5434/dashman_test"如上面的链接?...您是否还尝试按照文档中的示例添加POSTGRES_PASSWORD: "some password"?...
标签: java spring postgresql spring-boot circleci