FeignClien t注册 bean 为空问题,跪求大神帮帮忙看看
spring吧
全部回复
仅看楼主
level 1
hey702 楼主
Api工程:
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
@FeignClient(value =“NUMCLOUD-PROVIDER”)
public interface TestNumberProvider {
@RequestMapping(“/ hi”)
public String getCount();
}
客户端的启动类:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableEurekaClient
@SpringBootApplication(scanBasePackages = {com.number.controller“})
@EnableFeignClients(”com.numGroup.number.api“
public class NumCloudConsumerApplication {
public static void main(String [] args){
SpringApplication.run(NumCloudConsumerApplication.class,args);
}
}
报错信息:
描述:
字段testNumberProvider在com.numGroup.number.controller.TestClientController所需类型的豆“cn.js189.numGroup.number.api.TestNumberProvider”不能被发现。
注入点具有以下注释:
- @ org.springframework.beans.factory.annotation.Autowired(required = true)
操作:
考虑在配置中定义类型为“com.numGroup.number.api.TestNumberProvider”的bean。
spring版本:
<parent>
<groupId> org.springframework.boot </ groupId>
<artifactId> spring-boot-starter-parent </ artifactId>
<version> 2.1.0.RELEASE </ version>
<relativePath /> <! - 从存储库查找父级 - >
</ parent>
<dependencyManagement>
<dependencies >
<dependency>
<groupId> org.springframework.cloud </ groupId>
<artifactId> spring-cloud-dependencies </ artifactId>
<version> Greenwich.M1 </ version>
<type> pom </ type>
<scope> import </ scope>
</ dependency>
</ dependencies>
</ dependencyManagement>
2018年11月09日 09点11分 1
level 1
Application 添加 @EnableFeignClients , 否则spring boot 依赖注入中接口找不到实现。
2020年04月28日 09点04分 2
1