开发者学堂课程【精通Spring Cloud Alibaba:Openfeign客户端调用命名规范】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/634/detail/10082
Openfeign客户端调用命名规范
微服务架构基本的样式最大的优点能够对我们 feign 实现复用机制。
注意 feign 客户端调用的事项:
如果请求参数没有加上注解的话,默认采用 post 请求发送
Openfeign,默认是支持负载均衡, ribbon。
Nacos 服务注册服务名称是否有下划线。
在微服务架构中服务的名称命名不能够有下划线。
Rest、openfeign 都学习.
SpringGloud.与SpringGloudalibaba有区别。
代码如下:
@FeignClient("meitemayikt-member")
public interface MemberServiceFeign {
**
*提供我们发布的接口
@param userId
@return
@GetMapping("/getuser")
String getUser(@RequestParam("userId") Integer userId);
Ispring:
application:
###服务的名称
name: meitemayikt-member
cloud:
nacos:
discovery:
###nacos注册地址
server-addr: 127.0.0.1:8848
server:
port:8081
2020-01-09 22:01:57.546 INFO 1729704 ---[
main] ConfigServletWebServerApplicationContext:
Refreshing org.springframework.boot.web.servlet.context
.AnnotationConfigServletWebServerApplicationContext@9573584: startup date [Thu Jan 09 22:01:57 CST
2020]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@3e92efc3
2020-01-09 22:01:57.719 ERROR 1729704 ---[
main] o.s.boot.SpringApplication
Application run failed
java.lang.IllegalStateException: Service id not legal hostname (meitemayikt_member)
at org.springframework.util.Assert.state(Assert.java:73)~[spring-core-5.0.4.RELEASE.jar:5.0.4
.RELEASE]
at org.springframework.cloud.openfeign.FeignClientsRegistrar.getName(FeignCl[entsRegistrar.java:237)
S~[spring-cloud-openfeign-core-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerFeignClient
(FeignClientsRegistrar.java:172)~[spring-cloud-openfeign-core-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerFeignclients
(FeignClientsRegistrar.java:158)~[spring-cloud-openfeign-core-2.0.0.RELEASE.jar:2.0.0.REL可】
at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerBeanDefinitions
(FeignClientsRegistrar.java:83)~[spring-cloud-openfeign-core-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader
!annotation.getClass(attributeName:"fallback").isInterface(),
message:"Fallback class must implement the interface annotated by @Fe
D
Assert.isTrue(
!annotation.getClass(attributeName:"fallbackFactory").isInterface(),
message:"Fallback factory must produce instances of fallback classes
/* for testing */ String getName(Map attributes){
String name =(String) attributes.get("serviceld");
if (!StringUtils.hasText(name)){
name =(String) attributes.get("name");
if (!StringUtils.hasText(name)){
name =(String) attributes.get("value");