我有一個Spring Boot應用程序,目前在Heroku的CI中構建和運行測試,我也試圖讓它在Circle CI中工作。我的配置文件看起來像這樣:在CircleCi中從Spring Boot訪問PostgreSQL 9.6
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://[email protected]: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://[email protected]: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://[email protected]:5434/dashman_test
- image: postgres:9.6
environment:
POSTGRES_USER: dashman_test
POSTGRES_DB: dashman_test
TEST_DATABASE_URL: postgresql://[email protected]/circle_test?sslmode=disable
DATABASE_URL: postgresql://[email protected]/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://[email protected]:5434/circle_test?sslmode=disable
DATABASE_URL: postgres://dashman_test:[email protected]: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
@StanislavL:我添加了我試過的每個DATABASE_URL的列表。那是你問的嗎? – Pablo
難道它不是postgree在碼頭集裝箱中運行,因此而不是本地主機,您需要容器IP(或名稱)? – StanislavL