[英]Spring Boot with spring-cloud: gradle build fails
./gradlew build
fails with the error given at the bottom while running :test
task. ./gradlew build
失败,并在运行:test
任务时显示底部错误。 The code just checks if the context is loaded properly. 该代码仅检查上下文是否正确加载。
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class RegistryApplicationTests {
@Test
public void contextLoads() {
}
}
The bootstrap.yml file is given below(pretty standard), I'm not sure why it is trying to load the property file from the cloud-config service, how do I work around it?? 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
Stack Trace 堆栈跟踪
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 As suggested by @dzatorsky tried adding @Profile("test")
and @ActiveProfiles("test")
, DID NOT WORK . 更新内容建议通过@dzatorsky尝试添加@Profile("test")
和@ActiveProfiles("test")
没有工作 。
Tried manually adding the property file for the test using @TestPropertySource(locations = "file:src/test/resources/application-test.yml")
DID NOT WORK 手动尝试使用添加属性文件的测试@TestPropertySource(locations = "file:src/test/resources/application-test.yml")
没有工作
Finally overrode using @TestPropertySource(properties = {"spring.cloud.config.fail-fast=false"})
which worked, but it looks like a very ugly work around 最后使用@TestPropertySource(properties = {"spring.cloud.config.fail-fast=false"})
覆盖了它,但是看起来很丑陋
The Inference is bootstrap.yml
in src/main/resources
overrides the properties specified anywhere else, tried renaming application-test.yml to bootstrap.yml in src/test/resources
WORKED . 推理是bootstrap.yml
中src/main/resources
属性指定的其他地方覆盖,试图重命名application-test.yml to bootstrap.yml in src/test/resources
的工作 。
Is this the cleaner way getting this done? 这是完成这项工作的更干净的方法吗?
Error on GET request for " http://localhost:8888/registry/default ": Connection refused: connect; GET请求“ http:// localhost:8888 / registry / default ”时出错:连接被拒绝:connect; nested exception is java.net.ConnectException: Connection refused 嵌套的异常是java.net.ConnectException:连接被拒绝
Seems that your Spring Cloud Config server is down. 似乎您的Spring Cloud Config服务器已关闭。
UPDATE : If you want to run your tests without running Config Server (which is a right thing to do in the most cases) then I would suggest doing the following: UPDATE :如果您想在不运行Config Server的情况下运行测试(在大多数情况下是正确的选择),那么我建议您执行以下操作:
Add application-test.yml with the following content: 添加具有以下内容的application-test.yml:
cloud:
config:
fail-fast: false
Annotate your test class with: 使用以下注释注释测试类:
@Profile("test")
In this case, whenever you run your tests they use a default parameters defined in application.yml plus those that you override in application.test.yml. 在这种情况下,无论何时运行测试,它们都会使用application.yml中定义的默认参数以及您在application.test.yml中覆盖的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.