FeignClients Unsatisfied dependency expressed through field ‘iFeignClientService‘; ...

10 篇文章 0 订阅
2 篇文章 0 订阅

目录

一,报错信息

二,写法

(一)  service

(二)  控制器调用

三,解决办法


 

 

一,报错信息

2020-10-16 10:58:59.622  WARN 1004 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TController': Unsatisfied dependency expressed through field 'iFeignClientService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sgfd.service.IFeignClientService': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException
2020-10-16 10:58:59.622  INFO 1004 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

 

 

二,写法

(一)  service

package com.sgfd.service;

import java.util.Map;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@FeignClient(url="localhost:8088" ,value = "项目名称" )
@RequestMapping("/t")
public interface IFeignClientService {	
	
	/**
     * 物联管理平台下发app镜像仓库地址及相关数据到边设备
     */
    @RequestMapping("/t1")
    @ResponseBody
    public String t1(@RequestBody Map<String,String> map) ;  	
    
}

(二)  控制器调用

package com.controller;

import com.sgfd.feign.IFeignClientService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TControllerextends {

	@Autowired 
	IFeignClientService  iFeignClientService;
	
	@Override
	public void test(){
		Map<String, String> operationMap = new HashMap<>();
		operationMap.put("container", "1");//镜像名称
		operationMap.put("version", "2");//镜像版本
		operationMap.put("app", "3");//应用名称
		operationMap.put("control", "4");//  1启动2停止3删除
		iFeignClientService.t1(operationMap)
	}
	
}

三,解决办法

    一开始我以为是大众化的使用问题,注解没写完啊,启动类没加注解啊,包的问题等等。后来都没找对对应的解决办法。于是去看了下官方文档。下面这段话是关键,FeignClient注解失效了。

     在使用FeignClient时,Spring会按name创建不同的ApplicationContext,通过不同的Context来隔离FeignClient的配置信息,在使用配置类时,不能把配置类放到Spring App Component scan的路径下,否则,配置类会对所有FeignClient生效.

 

于是把远程调用的单独分出包,EnableFeignClients注解的路径也变一下

package com.sgfd.feign;

     IFeignClientService 

 

Application

    @SpringBootApplication(scanBasePackages = {"com.sgfd.service","com.sgfd.controller","com.sgfd.mode"})
    @EnableFeignClients(basePackages="com.sgfd.feign")

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用。 引用。 引用。 问题: unsatisfied dependency expressed through field是什么意思? 回答: "unsatisfied dependency expressed through field"表示在Spring框架中的依赖注入过程中发生了问题。具体地说,在引用的代码中,通过字段注入方式存在依赖不满足的情况。这通常是由于依赖对象无法被正确创建或注入所导致的。在这种情况下,通常会抛出UnsatisfiedDependencyException异常,其中包含详细的错误信息和根本原因。在你的情况中,报错信息指出在'logInfoServiceImpl'类的'baseMapper'字段上存在依赖不满足的问题,导致无法创建该对象。你检查了配置文件和映射文件,但仍然无法解决问题。你可能需要进一步检查依赖注入的配置和相关的bean定义,确保依赖注入过程正确进行。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [记录:Unsatisfied dependency expressed through field ‘XxxService‘...【亲测有效】](https://blog.csdn.net/weixin_43970743/article/details/124378426)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Unsatisfied dependency expressed through field 'baseMapper'解决方法](https://blog.csdn.net/zjwl199802/article/details/103713864)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值