2017-06-22 67 views
2

./gradlew build失败,并在运行:test任务时在底部给出的错误。代码只是检查上下文是否正确加载。弹簧云与弹簧云:gradle构建失败

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

    @Test 
    public void contextLoads() { 
    } 
} 

的bootstrap.yml文件如下(非常标准),我不知道为什么它试图加载从云配置服务的属性文件,我怎么解决它?给出

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 

UPDATE 作为建议的@dzatorsky尝试添加@Profile("test")@ActiveProfiles("test")没有工作

手动尝试添加使用测试属性文件@TestPropertySource(locations = "file:src/test/resources/application-test.yml")没有工作

使用@TestPropertySource(properties = {"spring.cloud.config.fail-fast=false"})其工作最后推翻,但它看起来像一个非常丑陋的变通

的推理是src/main/resourcesbootstrap.yml覆盖其他地方指定的属性,尝试重命名application-test.yml to bootstrap.yml in src/test/resourcesWORKED

这是干净的方式来完成这项工作吗?

+0

非常好的解释...对我来说,最后的解决方案也可以。..工作人员 – emkays

回答

1

对“http://localhost:8888/registry/default”的GET请求出错:连接被拒绝:连接;嵌套的例外是java.net.ConnectException:连接被拒绝

看来你春云配置服务器已关闭。

UPDATE:如果您要在不运行配置服务器(这是在大多数情况下,做正确的事)运行测试,那么我会建议做以下几点:

添加应用test.yml具有以下内容:

cloud: 
    config: 
     fail-fast: false 

注释测试类:

@Profile("test") 

在这种情况下,只要你运行你的测试,他们使用application.yml中定义的默认参数以及你在application.test.yml中重写的参数。

+0

这是在执行时:测试。 –

+0

将'fail-fast'属性更改为'true'以进行测试。 – spencergibb

+0

我已经更新了我的答案并考虑了上述评论。 –