繁体   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