我有一个使用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="postgresql://dashman_test@localhost:5434/dashman_test"
引用起来吗?你是否也尝试按照文档中的示例添加POSTGRES_PASSWORD: "some password"
? - Vao Tsun