Feign (a) using a simple process of recording feign

A dependent

Spring Cloud version information

1 <properties>
2     <spring-cloud.version>Greenwich.SR2</spring-cloud.version>
3 </properties>

openfeign dependence 

 1 <dependencies>
 2     <dependency>
 3       <groupId>org.springframework.cloud</groupId>
 4       <artifactId>spring-cloud-starter-openfeign</artifactId>
 5     </dependency>
 6 </dependencies>
 7 <dependencyManagement>
 8     <dependencies>
 9       <dependency>
10         <groupId>org.springframework.cloud</groupId>
11         <artifactId>spring-cloud-dependencies</artifactId>
12         <version>${spring-cloud.version}</version>
13         <type>pom</type>
14         <scope>import</scope>
15       </dependency>
16     </dependencies>
17 </dependencyManagement>

 Two, Application Note:

@EnableFeignClients

Three, FeignService:

May be used alone value / name, you may also be used value / name url and methods used in combination;

1 @FeignClient(name = "org-feign-service", url = "http://localhost:8080/o/org")
1 /**
2      * @return The service id with optional protocol prefix. Synonym for {@link #value()
3      * value}.
4      */
5     @AliasFor("value")
6     String name() default "";
1 /**
2      * @return an absolute URL or resolvable hostname (the protocol is optional).
3      */
4     String url() default "";
1 /**
2      * The name of the service with optional protocol prefix. Synonym for {@link #name()
3      * name}. A name must be specified for all clients, whether or not a url is provided.
4      * Can be specified as property key, eg: ${propertyKey}.
5      * @return the name of the service with optional protocol prefix
6      */
7     @AliasFor("name")
8     String value() default "";
Note: the parameter passing method arguments FeignService. To form and be called consistent with the Controller
1    /**
2      * @param org_id
3      * @return
4      */
5     @GetMapping("/{org_id}")
6     Org findById(@PathVariable(name = "org_id") int org_id);
1   /**
2      * @param org_id
3      * @return
4      */
5     @GetMapping("/{org_id}")
6     public List<Org> findById(@PathVariable(name = "org_id") int org_id) {
7                 ...处理操作...
8         return  orgList;
9     } 

Fourth, the use FeignService in the Controller:

1    @Autowired
2     private OrgFeignService orgFeignService;

 

Guess you like

Origin www.cnblogs.com/zy-stu/p/zy_feign_sty_01.html