首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Netflix假装例外

Netflix假装例外
EN

Stack Overflow用户
提问于 2017-02-03 21:13:54
回答 2查看 1.1K关注 0票数 1

依赖关系

org.springframework.cloud:spring-cloud-starter-feign:jar:1.2.2.RELEASE:compile com.netflix.feign:feign-core:jar:8.16.2:compile com.netflix.feign:feign-slf4j:jar:8.16.2:compile com.netflix.feign:feign-jackson:jar:8.15.1:compile

在SpringBootAppilication上实现冒充

@EnableFeignClients(basePackages = "com.vett.services.bucket.restclient")

冒充接口客户端

@FeignClient(name = "myClient", configuration = ClientConfigs.class, url = "https://my-endpoint"); public interface MyClient {

导致这一错误

org.springframework.core.annotation.AnnotationConfigurationException: Attribute 'value' in annotation [org.springframework.cloud.netflix.feign.FeignClient] must be declared as an @AliasFor [serviceId], not [name]

到目前为止我已经

由于我不清楚我使用了value而不是name的问题是什么,我的搜索没有成功--我看到了一些假注释的问题,但一点也不像这一点。

EN

回答 2

Stack Overflow用户

发布于 2017-02-09 15:49:18

我遇到了同样的问题,一旦我添加了下面的依赖项,它就开始工作了:

代码语言:javascript
复制
dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.SR7"}
}

我使用的是Spring 1.4,但是Spring4.3.6。也是春季假1.2.5

票数 1
EN

Stack Overflow用户

发布于 2022-01-11 08:12:57

当使用多个伪客户端或错误的包结构时,可能会发生此错误。有时由于版本不兼容而发生此错误,但在某些项目中,我们可能无法更改版本。因此,您可以使用以下代码解决此问题。这个密码对我有用。

在ApplicationStarter类中使用此注释:

代码语言:javascript
复制
@EnableFeignClients

冒充客户端接口:

代码语言:javascript
复制
import org.springframework.cloud.netflix.feign.FeignClient;

@FeignClient(value = "account-service", url = "${feign.client.account-service}", path = "/account/api/v1")
public interface AccountServiceClient {
  @RequestLine("POST  /customer/{email}/?name={accountName}")
  Long registerCustomer(@Param("email") String email, @Param("accountName") String accountName);
}

为多个伪用法定义bean:

代码语言:javascript
复制
@Bean
@Qualifier("account-feign-client")
public AccountServiceClient accountServiceClient() {
    return Feign.builder().target( AccountServiceClient.class,"${feign.client.account-service}");
}

@Bean
@Qualifier("mail-feign-client")
public MailServiceClient mailServiceClient() {
    return Feign.builder().target( MailServiceClient.class,"${feign.client.mail-service}");
}

使用中的自动提款机:

代码语言:javascript
复制
@Autowired
@Qualifier("account-feign-client")
private AccountServiceClient accountServiceClient;

pom.xml:

代码语言:javascript
复制
    <dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring.boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Brixton.SR7</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-feign</artifactId>
        <version>1.4.7.RELEASE</version>
    </dependency>
...
</dependencies>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42033109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档