簡體   English   中英

帶有Spring-Cloud的Spring Boot:gradle構建失敗

[英]Spring Boot with spring-cloud: gradle build fails

./gradlew build失敗,並在運行:test任務時顯示底部錯誤。 該代碼僅檢查上下文是否正確加載。

@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class RegistryApplicationTests {

    @Test
    public void contextLoads() {
    }
}

bootstrap.yml文件在下面給出(相當標准),我不確定為什么要嘗試從cloud-config服務加載屬性文件,我該如何解決?

spring:
 application:
   name: registry
 profiles:
   active: default
 cloud:
   config:
     uri: http://localhost:8888
     fail-fast: true

eureka:
  instance:
    prefer-ip-address: true
  client:
    registerWithEureka: false
    fetchRegistry: false
    server:
      waitTimeInMsWhenSyncEmpty: 0

堆棧跟蹤

Caused by: java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:130)
    at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:89)
    at 
    ....
    ....
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8888/registry/default": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666)
    at 
    ....
    ....
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at 

更新內容建議通過@dzatorsky嘗試添加@Profile("test")@ActiveProfiles("test") 沒有工作

手動嘗試使用添加屬性文件的測試@TestPropertySource(locations = "file:src/test/resources/application-test.yml") 沒有工作

最后使用@TestPropertySource(properties = {"spring.cloud.config.fail-fast=false"})覆蓋了它,但是看起來很丑陋

推理是bootstrap.ymlsrc/main/resources屬性指定的其他地方覆蓋,試圖重命名application-test.yml to bootstrap.yml in src/test/resources 的工作

這是完成這項工作的更干凈的方法嗎?

GET請求“ http:// localhost:8888 / registry / default ”時出錯:連接被拒絕:connect; 嵌套的異常是java.net.ConnectException:連接被拒絕

似乎您的Spring Cloud Config服務器已關閉。

UPDATE :如果您想在不運行Config Server的情況下運行測試(在大多數情況下是正確的選擇),那么我建議您執行以下操作:

添加具有以下內容的application-test.yml:

cloud:
    config:
        fail-fast: false

使用以下注釋注釋測試類:

@Profile("test")

在這種情況下,無論何時運行測試,它們都會使用application.yml中定義的默認參數以及您在application.test.yml中覆蓋的參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM