./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/resources
bootstrap.yml
覆盖其他地方指定的属性,尝试重命名application-test.yml to bootstrap.yml in src/test/resources
WORKED。
这是干净的方式来完成这项工作吗?
非常好的解释...对我来说,最后的解决方案也可以。..工作人员 – emkays