记一个nacos/openfeign遇到的问题,找到解决方法,但是不知原因

在alibaba cloud 中引入了nacos组件后,main方法启动的时候,出现了报错。

在网上百度了原因,有三种方法

1、将main放置与controller包 同级 可以解决

2、在main文件中加入

@SpringBootApplication(scanBasePackages = {"包名"})

3、创建一个

@Configuration
public class IClientConfig {
 
    @Bean
    public DefaultClientConfigImpl iClientConfig(){
        return new DefaultClientConfigImpl();
    }
}

使用第三种方法后 项目可以正常启动,但是当引入了openFeign之后,在调用nacos提供者接口的时候,报错了

java.lang.NullPointerException: null
	at org.springframework.cloud.openfeign.ribbon.FeignLoadBalancer.<init>(FeignLoadBalancer.java:76) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory.create(CachingSpringLoadBalancerFactory.java:64) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient.lbClient(LoadBalancerFeignClient.java:120) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient.execute(LoadBalancerFeignClient.java:82) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:110) ~[feign-core-10.4.0.jar:na]

网上搜寻解决办法的时候,发现是由于手动创建了一个 IClientConfig类,导致feign找不到namespace。所以,第三种方法是不能用的。

最终的结论,如果想nacos+openFeign 就要使用第二种方法,毕竟把main放到包的最内层去也不是正常的写法。

但是为什么第三种方法不行,第二种方法可以,我也不知道原因。

当然也有可能 我的pom引入的版本不对 导致会出现这情况。如果有人知道原因,可以告诉我下。谢谢。

我项目目前的pom版本

 <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.2.3.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
<!--spring boot 2.2.2-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.2.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--spring cloud Hoxton.SR1-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR8</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值