如何解决带有 @RestClientTest 和 @FeignAutoConfiguration 的 Spring 测试不起作用
我有以下配置:
@SpringBootApplication
@EnableFeignClients
public class Application {
@FeignClient(name = "theclient")
public interface TheClient {
...
theclient:
ribbon:
listOfServers: http://server:8080
并进行以下测试:
@RunWith(SpringRunner.class)
@RestClientTest(TheClient.class)
@ImportAutoConfiguration(
classes = {
RibbonAutoConfiguration.class,FeignRibbonClientAutoConfiguration.class,FeignAutoConfiguration.class
}
)
public class TheClientTest {
...
我得到的错误是 Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: theclient
,好像 application.yaml
没有被读取。但是,如果我添加一个带有 config.properties
的 theclient.ribbon.listOfServers=http://server:8080
文件,则测试会工作并通过。
使用 @TestPropertySource("classpath:application.yaml")
我在日志中看到 propertySourceLocations = '{classpath:application.yaml}'
但我会得到同样的错误。
我还尝试通过添加以下内容来禁用功能区:
spring:
cloud:
loadbalancer:
ribbon:
enable: false
但它不起作用。
感谢您的意见和帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。