微起来 微服务 Feign

将网络接口映射到本地。

FeignClient注解的使用介绍
由这篇猜测,之所以用url就是写死,就是因为还没搞服务发现。


在这里插入图片描述

<dependencies>
        <dependency>
            <groupId>com.xxx.yyy</groupId>
            <artifactId>workflow-service-api</artifactId>
            <version>1.1.7-SNAPSHOT</version>
        </dependency>
       
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

spring ioc不会自动为外部引入的其他服务jar包里,标注了@FeignClient注解的interface自动生成bean对象:正确的做法应该是明确指定basePackages的路径

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
@EnableTransactionManagement
@Import({DynamicDataSourceConfig.class, ServiceInfoUtil.class})
@EnableScheduling
@EnableAsync
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"com.xxx.sfp.workflow.api"})
public class BaseApplication extends SpringBootServletInitializer {

	public static void main(String[] args) {
		TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));

		System.setProperty("rocketmq.client.log.loadconfig","false");
		SpringApplication.run(BaseApplication.class, args);
	}
package com.xxx.api;

@FeignClient(
    value = "workflow-service",
    url = "${workflow-service.url}"
)
public interface FlowService {
    @PostMapping({"/api/v1/workflow/recruit/start"})
    JsonResult<TaskBean> startFlow(@RequestBody Map<String, Object> param);

    @PutMapping({"/api/v1/workflow/recruit/cancel"})
    JsonResult<TaskBean> cancel(@RequestBody Map<String, Object> param);

    @PutMapping({"/api/v1/workflow/recruit/turn"})
    JsonResult<TaskBean> turn(@RequestBody Map<String, Object> param);

    @PutMapping({"/api/v1/workflow/recruit/taskFinish"})
    JsonResult<TaskBean> taskFinish(@RequestBody Map<String, Object> param);

    @PutMapping({"/api/v1/workflow/recruit/reject"})
    JsonResult<TaskBean> reject(@RequestBody Map<String, Object> param);

    @PostMapping({"/api/v1/workflow/pms/start"})
    JsonResult<ProcessStratDto> pmsStart(@RequestBody ProcessStratDto dto);

    @PutMapping({"/api/v1/workflow/pms/apply"})
    JsonResult<ProcessApplyDto> pmsApply(@RequestBody ProcessApplyDto dto);

    @PutMapping({"/api/v1/workflow/pms/reject"})
    JsonResult<ProcessRejectDto> pmsReject(@RequestBody ProcessRejectDto dto);

    @PostMapping({"/api/v1/workflow/tesla/start"})
    JsonResult<TeslaProcessStartDto> teslaStart(@RequestBody TeslaProcessStartDto dto);

    @PostMapping({"/api/v1/workflow/tesla/startReturn"})
    JsonResult<TeslaReturnProcessStartDto> teslaReturnStart(@RequestBody TeslaReturnProcessStartDto dto);

    @PutMapping({"/api/v1/workflow/tesla/apply"})
    JsonResult<TeslaProcessApplyDto> teslaApply(@RequestBody TeslaProcessApplyDto dto);

    @PutMapping({"/api/v1/workflow/tesla/applyReturn"})
    JsonResult<TeslaReturnProcessApplyDto> teslaApplyReturn(@RequestBody TeslaReturnProcessApplyDto dto);

    @PutMapping({"/api/v1/workflow/tesla/cancel"})
    JsonResult<TeslaProcessCancelDto> teslaCancel(@RequestBody TeslaProcessCancelDto dto);

    @PutMapping({"/api/v1/workflow/user/getAdministrationByDepartureArea/{departureArea}"})
    JsonResult<String> getdministrationByDepartureArea(@PathVariable("departureArea") String departureArea);

    @PutMapping({"/api/v1/workflow/common/commonReject"})
    JsonResult<CommonProcessRejectDto> commonReject(@RequestBody CommonProcessRejectDto dto);

    @PutMapping({"/api/v1/workflow/common/commonRollback"})
    JsonResult<CommonProcessRollbackDto> commonRollback(@RequestBody CommonProcessRollbackDto dto);

    @PutMapping({"/api/v1/workflow/common/commonWithdraw"})
    JsonResult<CommonProcessWithdrawDto> commonWithdraw(@RequestBody CommonProcessWithdrawDto dto);

    @PutMapping({"/api/v1/workflow/common/commonTurn"})
    JsonResult<CommonProcessTurnDto> commonTurn(@RequestBody CommonProcessTurnDto dto);

    @PutMapping({"/api/v1/workflow/common/commonRestart"})
    JsonResult<CommonProcessRestartDto> commonRestart(@RequestBody CommonProcessRestartDto dto);

    @PutMapping({"/api/v1/workflow/common/commonBatchApply"})
    JsonResult<CommonProcessBatchApplyDto> commonBatchApply(@RequestBody CommonProcessBatchApplyDto dto);

    @PutMapping({"/api/v1/workflow/common/commonBatchReject"})
    JsonResult<CommonProcessBatchRejectDto> commonBatchReject(@RequestBody CommonProcessBatchRejectDto dto);

    @PostMapping({"/api/v1/workflow/drivingLicence/start"})
    JsonResult<DrivingLicenceProcessStartDto> dlStart(@RequestBody DrivingLicenceProcessStartDto dto);

    @PutMapping({"/api/v1/workflow/drivingLicence/approval"})
    JsonResult<DrivingLicenceProcessApprovalDto> dlApproval(@RequestBody DrivingLicenceProcessApprovalDto dto);

    @PostMapping({"/api/v1/workflow/travelFlow/start"})
    JsonResult<TravelFlowProcessStratDto> travelStart(@RequestBody TravelFlowProcessStratDto dto);

    @PutMapping({"/api/v1/workflow/travelFlow/apply"})
    JsonResult<TravelFlowProcessApplyDto> travelApply(@RequestBody TravelFlowProcessApplyDto dto);

    @PostMapping({"/api/v1/workflow/laborWorker/start"})
    JsonResult<LaborWorkerProcessStratDto> laborWorkerStart(@RequestBody LaborWorkerProcessStratDto dto);

    @PutMapping({"/api/v1/workflow/laborWorker/apply"})
    JsonResult<LaborWorkerProcessApplyDto> laborWorkerApply(@RequestBody LaborWorkerProcessApplyDto dto);
}


java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have available server for client: ms-oa
服务端没起 (可能环境切错了,dev不存在其他微服务)

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.xxx.TestRedis': Unsatisfied dependency expressed through field 'oaHcFaceService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xxx.base.modules.oa.api.OaHcFaceService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
	

启动类改成:
@EnableFeignClients(basePackages = {“com.xxx.sfp.workflow.api”})
@EnableFeignClients(basePackages = {“com.xxx.sfp.workflow.api”,“com.cowain.base.modules.*”})

https://blog.csdn.net/weixin_43818327/article/details/100776066
解决java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have availa
一般消费者会过一会(大概几十秒)会从注册中心拿一次提供者列表,一般刚启动的提供者虽然在注册中心注册了,但是消费者那边极有可能还不知道他起来了,所以等一会一般就好了

feign.RetryableException: connect timed out executing GET http://ms-oa/oa/app/hc/refresh-schedule
没有指定url
@FeignClient(name = “ms-oa”, path = “/oa”)
@FeignClient(name = “ms-oa”, path = “/oa”,url = “${oa-service.url}”)

workflow-service:
url:
空。这东西只是个路由标识?由网关转到具体的。(似乎也没配啊)
***(${oa-service.url} 但我不知道这玩意应该在哪配,我看workflow yml置空,但实际是有ip端口的,我照做,没用,是真空了。从网关里翻到了,把它写死了)

@FeignClient(name = "ms-oa", path = "/oa",url = "http://10.2.2.222:31609")
public interface OaHcFaceService {
  //   url = "${workflow-service.url}"
    @GetMapping({"/app/hc/refresh-schedule"})
    R refreshSchedule();
}

feign.codec.DecodeException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.cowain.base.common.utils.R] and content type [text/plain;charset=UTF-8]

接收值错掉了,服务我只返回了String,没用JsonResult。订阅者用JsonResult接收本身就会报错。但是注意到text/plain和application/json
猜测:也许是@RestController对String这种数据类型不起效吧

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值