SpringCloud-feign01

概述

Feign能干什么

feign旨在使編寫java http客戶端變的更容易
前面在使用Ribbon+RestTemplate時(shí),利用RestTemplate對(duì)http請(qǐng)求的封裝處理所刀,形成了一套膜版畫的調(diào)用方法。但是在實(shí)際開發(fā)中山涡,由于對(duì)服務(wù)依賴的調(diào)用可能不止一處幻碱,往往一個(gè)接口會(huì)被多處調(diào)用狂秦,所以通常都會(huì)針對(duì)每個(gè)微服務(wù)自行封裝一些客戶端類來包裝這些依賴服務(wù)的調(diào)用。所以治专,F(xiàn)eign在此基礎(chǔ)上做了進(jìn)一步封裝卖陵,由他來幫助我們定義和實(shí)現(xiàn)依賴服務(wù)接口的定義。在Feign的實(shí)現(xiàn)下张峰,我們只需要?jiǎng)?chuàng)建一個(gè)接口并使用注解的方式來配置他(以前是在DAO接口上面標(biāo)注Mapper注解泪蔫,現(xiàn)在是在一個(gè)微服務(wù)接口上面標(biāo)注一個(gè)Feign注解即可),即可完成對(duì)服務(wù)提供方的接口綁定,簡(jiǎn)化了使用Spring cloud Ribbon時(shí)喘批,自動(dòng)封裝服務(wù)調(diào)用客戶端的開發(fā)量撩荣。

Feign集成了Ribbon

利用Ribbon維護(hù)了SPRINGBOOT-MYBATIS-PROVIDER-001的服務(wù)列表信息,并且通過輪詢實(shí)現(xiàn)了客戶端的負(fù)載均衡饶深。而與Ribbon不同額是餐曹,通過feign只需要定義服務(wù)綁定接口且以聲明式的方法,優(yōu)雅而簡(jiǎn)單的實(shí)現(xiàn)了服務(wù)調(diào)用

公共api中包括要提供出去的服務(wù)接口以及實(shí)體類敌厘,在此先上一些踩過的坑

當(dāng)api項(xiàng)目的pom.xml中依賴的是下面代碼中的包時(shí)

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
            <version>1.4.7.RELEASE</version>
        </dependency>

服務(wù)提供者依賴了api包台猴,啟動(dòng)類啟動(dòng)時(shí)報(bào)如下錯(cuò)誤

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.hc.config.SwaggerConfig]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class] cannot be opened because it does not exist
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:596) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.access$900(ConfigurationClassParser.java:108) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports$1(ConfigurationClassParser.java:805) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_191]
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:801) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:771) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:185) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at com.hc.ApplicationProvider001.main(ApplicationProvider001.java:90) [classes/:na]
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:51) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:86) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:73) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:682) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getRelated(ConfigurationClassParser.java:1074) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getAnnotationAttributes(ConfigurationClassParser.java:1055) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.collectImports(ConfigurationClassParser.java:538) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:511) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:302) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:586) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    ... 19 common frames omitted

最終經(jīng)查證,發(fā)現(xiàn)feign的包應(yīng)該依賴如下:

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>2.1.2.RELEASE</version>
        </dependency>

-----------end----------最終解決了提供者啟動(dòng)報(bào)錯(cuò)問題俱两。

=================================================================

springboot-mybatis-consumer-feign中的代碼如下:

啟動(dòng)類

package com.hc;
import org.apache.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"com.hc"})  //使用feign代替ribbon
public class AppUserConsumerFeign001 {
    private static Logger logger = Logger.getLogger(AppUserConsumerFeign001.class);
    /**
     * Start
     */
    public static void main(String[] args) {
        SpringApplication.run(AppUserConsumerFeign001.class, args);
//        logger.info("SpringBoot Start Success");
    }
}

controller類

package com.hc.controller;

import com.hc.model.User;
import com.hc.service.UserClientService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 */
@Controller
@RequestMapping("/consumerFeign001")
public class UserClientController {

    private Logger logger = Logger.getLogger(UserClientController.class);

    @Autowired
    UserClientService userClientService;

    @RequestMapping("/getUsers")
    @ResponseBody
    public List<User> getUsers() {
        return  userClientService.getUsers();
    }
}

依賴的公共接口提供模塊api(spring-mybatis-api)饱狂,代碼如下:

@FeignClient(value="SPRINGBOOT-MYBATIS-PROVIDER-001")
public interface UserClientService {
    @RequestMapping("/getUsers")
    List<User> getUsers();
}

服務(wù)提供者(springboot-mybatis-provider)controller中代碼如下:

@RequestMapping("/getUserInfo")
    @ResponseBody
    public List<User> getUserInfo() {
        List<User> userList = userService.getUserInfo();
        if(userList!=null){
            System.out.println("user.getName():"+userList.get(0).getName());
            logger.info("user.getAge():"+userList.get(0).getAge());
        }
        return userList;
    }
方法名不規(guī)范,請(qǐng)忽略宪彩,此方法是查詢所有用戶的

首次訪問結(jié)果如下:

報(bào)錯(cuò)信息

排查原因------------------------start--------------------------------------

發(fā)現(xiàn)api中提供的接口路徑與提供者提供的接口路徑不一致休讳,如下:

#api中service中代碼片段
@FeignClient(value="SPRINGBOOT-MYBATIS-PROVIDER-001")
public interface UserClientService {
    @RequestMapping("/getUsers")
    List<User> getUsers();
}

#提供者controller中代碼片段
@RequestMapping("/getUserInfo")
    @ResponseBody
    public List<User> getUserInfo() {
        List<User> userList = userService.getUserInfo();
        if(userList!=null){
            System.out.println("user.getName():"+userList.get(0).getName());
            logger.info("user.getAge():"+userList.get(0).getAge());
        }
        return userList;
    }

結(jié)果發(fā)現(xiàn)兩者的路徑不同,然后將api中的路徑與提供者controller中的路徑進(jìn)行統(tǒng)一

#api中service中代碼片段
@FeignClient(value="SPRINGBOOT-MYBATIS-PROVIDER-001")
public interface UserClientService {
    @RequestMapping("/getUserInfo")
    List<User> getUsers();
}

#提供者controller中代碼片段
@RequestMapping("/getUserInfo")
    @ResponseBody
    public List<User> getUserInfo() {
        List<User> userList = userService.getUserInfo();
        if(userList!=null){
            System.out.println("user.getName():"+userList.get(0).getName());
            logger.info("user.getAge():"+userList.get(0).getAge());
        }
        return userList;
    }

再次訪問毯焕,結(jié)果如下:

默認(rèn)feign使用的是輪詢算法

排查原因------------------------end--------------------------------------

注意:此處也給大家展示一個(gè)濤哥踩得大坑衍腥,這個(gè)坑是真的坑,而且是稍不注意就會(huì)導(dǎo)致大家話費(fèi)很長(zhǎng)的時(shí)間來找纳猫,并且不一定能找到的坑

api(springb-mybatis-api)中的原代碼,會(huì)導(dǎo)致springboot-mybatis-feign的啟動(dòng)報(bào)錯(cuò)

報(bào)錯(cuò)信息是這樣的

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userConsumerFeign002Controller': Unsatisfied dependency expressed through field 'userClientService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.hc.service.UserClientService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at com.hc.ApplicationConsumerfeign002.main(ApplicationConsumerfeign002.java:20) [classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.hc.service.UserClientService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:178) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1674) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1249) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:257) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1474) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1431) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1214) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1171) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    ... 19 common frames omitted
Caused by: java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
    at feign.Util.checkState(Util.java:130) ~[feign-core-10.2.3.jar:na]
    at org.springframework.cloud.openfeign.annotation.PathVariableParameterProcessor.processArgument(PathVariableParameterProcessor.java:52) ~[spring-cloud-openfeign-core-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.cloud.openfeign.support.SpringMvcContract.processAnnotationsOnParameter(SpringMvcContract.java:292) ~[spring-cloud-openfeign-core-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:110) ~[feign-core-10.2.3.jar:na]
    at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:188) ~[spring-cloud-openfeign-core-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:66) ~[feign-core-10.2.3.jar:na]
    at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:154) ~[feign-core-10.2.3.jar:na]
    at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:52) ~[feign-core-10.2.3.jar:na]
    at feign.Feign$Builder.target(Feign.java:251) ~[feign-core-10.2.3.jar:na]
    at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:36) ~[spring-cloud-openfeign-core-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:238) ~[spring-cloud-openfeign-core-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:267) ~[spring-cloud-openfeign-core-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:247) ~[spring-cloud-openfeign-core-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    ... 30 common frames omitted

產(chǎn)生這個(gè)錯(cuò)誤的原因如下

@FeignClient(value="SPRINGBOOT-MYBATIS-PROVIDER-001")
UserClientServiceFallbackFactory.class)
public interface UserClientService {

    @RequestMapping("/getUserInfo")
    List<User> getUsers();

    @RequestMapping(value = "/getRealUserInfo/{id}" , method = RequestMethod.GET)
//    原先不規(guī)范寫法會(huì)導(dǎo)致消費(fèi)端啟動(dòng)報(bào)錯(cuò)竹捉,大家一定要注意
    User getRealUserInfo(@PathVariable Integer id);
//     規(guī)范的寫法
//    User getRealUserInfo(@PathVariable("id") Integer id);
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末芜辕,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子块差,更是在濱河造成了極大的恐慌侵续,老刑警劉巖倔丈,帶你破解...
    沈念sama閱讀 218,525評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異状蜗,居然都是意外死亡需五,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,203評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門轧坎,熙熙樓的掌柜王于貴愁眉苦臉地迎上來宏邮,“玉大人,你說我怎么就攤上這事缸血∶郯保” “怎么了?”我有些...
    開封第一講書人閱讀 164,862評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵捎泻,是天一觀的道長(zhǎng)飒炎。 經(jīng)常有香客問我,道長(zhǎng)笆豁,這世上最難降的妖魔是什么郎汪? 我笑而不...
    開封第一講書人閱讀 58,728評(píng)論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮闯狱,結(jié)果婚禮上怒竿,老公的妹妹穿的比我還像新娘。我一直安慰自己扩氢,他們只是感情好耕驰,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,743評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著录豺,像睡著了一般朦肘。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上双饥,一...
    開封第一講書人閱讀 51,590評(píng)論 1 305
  • 那天媒抠,我揣著相機(jī)與錄音,去河邊找鬼咏花。 笑死趴生,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的昏翰。 我是一名探鬼主播苍匆,決...
    沈念sama閱讀 40,330評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼棚菊!你這毒婦竟也來了浸踩?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,244評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤统求,失蹤者是張志新(化名)和其女友劉穎检碗,沒想到半個(gè)月后据块,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,693評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡折剃,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,885評(píng)論 3 336
  • 正文 我和宋清朗相戀三年另假,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片怕犁。...
    茶點(diǎn)故事閱讀 40,001評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡边篮,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出因苹,到底是詐尸還是另有隱情苟耻,我是刑警寧澤,帶...
    沈念sama閱讀 35,723評(píng)論 5 346
  • 正文 年R本政府宣布扶檐,位于F島的核電站凶杖,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏款筑。R本人自食惡果不足惜智蝠,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,343評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望奈梳。 院中可真熱鬧杈湾,春花似錦、人聲如沸攘须。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,919評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽于宙。三九已至浮驳,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間捞魁,已是汗流浹背至会。 一陣腳步聲響...
    開封第一講書人閱讀 33,042評(píng)論 1 270
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留谱俭,地道東北人奉件。 一個(gè)月前我還...
    沈念sama閱讀 48,191評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像昆著,于是被迫代替她去往敵國(guó)和親县貌。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,955評(píng)論 2 355