Skip to content

Commit 42473bd

Browse files
committed
新增feign继承特性示例
1 parent 7bd58a1 commit 42473bd

File tree

10 files changed

+273
-0
lines changed

10 files changed

+273
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>eureka-feign-api</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>eureka-feign-api</name>
12+
<description>Spring Cloud In Action</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.6.RELEASE</version>
18+
<relativePath/>
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-web</artifactId>
30+
</dependency>
31+
</dependencies>
32+
33+
<dependencyManagement>
34+
<dependencies>
35+
<dependency>
36+
<groupId>org.springframework.cloud</groupId>
37+
<artifactId>spring-cloud-dependencies</artifactId>
38+
<version>Dalston.SR2</version>
39+
<type>pom</type>
40+
<scope>import</scope>
41+
</dependency>
42+
</dependencies>
43+
</dependencyManagement>
44+
45+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.didispace.api;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RequestParam;
5+
6+
/**
7+
* @author 翟永超
8+
* @create 2017/8/8.
9+
* @blog http://blog.didispace.com
10+
*/
11+
public interface HelloService {
12+
13+
@GetMapping("/hello")
14+
String hello(@RequestParam(value = "name") String name);
15+
16+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>eureka-feign-client</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>eureka-feign-client</name>
12+
<description>Spring Cloud In Action</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.6.RELEASE</version>
18+
<relativePath/>
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-web</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.cloud</groupId>
33+
<artifactId>spring-cloud-starter-eureka</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.didispace</groupId>
37+
<artifactId>eureka-feign-api</artifactId>
38+
<version>1.0.0</version>
39+
</dependency>
40+
</dependencies>
41+
42+
<dependencyManagement>
43+
<dependencies>
44+
<dependency>
45+
<groupId>org.springframework.cloud</groupId>
46+
<artifactId>spring-cloud-dependencies</artifactId>
47+
<version>Dalston.SR2</version>
48+
<type>pom</type>
49+
<scope>import</scope>
50+
</dependency>
51+
</dependencies>
52+
</dependencyManagement>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-maven-plugin</artifactId>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
63+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.didispace.api.impl;
2+
3+
import com.didispace.api.HelloService;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.builder.SpringApplicationBuilder;
6+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@EnableDiscoveryClient
10+
@SpringBootApplication
11+
public class Application {
12+
13+
@RestController
14+
class HelloController implements HelloService {
15+
16+
@Override
17+
public String hello(String name) {
18+
return "hello " + name;
19+
}
20+
21+
}
22+
23+
public static void main(String[] args) {
24+
new SpringApplicationBuilder(Application.class).web(true).run(args);
25+
}
26+
27+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spring.application.name=eureka-feign-client
2+
server.port=2101
3+
4+
eureka.client.serviceUrl.defaultZone=http://eureka.didispace.com/eureka/
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>eureka-feign-consumer</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>eureka-feign-consumer</name>
12+
<description>Spring Cloud In Action</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.6.RELEASE</version>
18+
<relativePath/>
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-web</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.cloud</groupId>
33+
<artifactId>spring-cloud-starter-eureka</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.cloud</groupId>
37+
<artifactId>spring-cloud-starter-feign</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.didispace</groupId>
41+
<artifactId>eureka-feign-api</artifactId>
42+
<version>1.0.0</version>
43+
</dependency>
44+
</dependencies>
45+
46+
<dependencyManagement>
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.springframework.cloud</groupId>
50+
<artifactId>spring-cloud-dependencies</artifactId>
51+
<version>Dalston.SR2</version>
52+
<type>pom</type>
53+
<scope>import</scope>
54+
</dependency>
55+
</dependencies>
56+
</dependencyManagement>
57+
58+
<build>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-maven-plugin</artifactId>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
67+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.didispace.api.consumer;
2+
3+
import com.didispace.api.HelloService;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.boot.builder.SpringApplicationBuilder;
7+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
8+
import org.springframework.cloud.netflix.feign.EnableFeignClients;
9+
import org.springframework.cloud.netflix.feign.FeignClient;
10+
import org.springframework.web.bind.annotation.GetMapping;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
@EnableFeignClients
14+
@EnableDiscoveryClient
15+
@SpringBootApplication
16+
public class Application {
17+
18+
@FeignClient("eureka-feign-client")
19+
interface HelloServiceClient extends HelloService {
20+
21+
}
22+
23+
@RestController
24+
class TestController {
25+
26+
@Autowired
27+
private HelloServiceClient helloServiceClient;
28+
29+
@GetMapping("/test")
30+
public String test(String name) {
31+
return helloServiceClient.hello(name);
32+
}
33+
34+
}
35+
36+
public static void main(String[] args) {
37+
new SpringApplicationBuilder(Application.class).web(true).run(args);
38+
}
39+
40+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spring.application.name=eureka-feign-consumer
2+
server.port=2102
3+
4+
eureka.client.serviceUrl.defaultZone=http://eureka.didispace.com/eureka/

2-Dalston版教程示例/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
<module>turbine</module>
3131
<module>turbine-amqp</module>
3232

33+
<module>eureka-feign-api</module>
34+
<module>eureka-feign-client</module>
35+
<module>eureka-feign-consumer</module>
36+
3337
<module>hystrix-collapser-provider</module>
3438
<module>hystrix-collapser-consumer</module>
3539

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
- [Spring Cloud实战小贴士:Zuul处理Cookie和重定向](http://blog.didispace.com/spring-cloud-zuul-cookie-redirect/)
6161
- [Spring Cloud实战小贴士:Zuul统一异常处理(一)](http://blog.didispace.com/spring-cloud-zuul-exception/)
6262
- [Spring Cloud实战小贴士:Zuul统一异常处理(二)](http://blog.didispace.com/spring-cloud-zuul-exception-2/)
63+
- [Spring Cloud实战小贴士:Zuul统一异常处理(三)【Dalston版】](http://blog.didispace.com/spring-cloud-zuul-exception-3/)
64+
- [Spring Cloud实战小贴士:Turbine如何聚合设置了context-path的Hystrix数据](http://blog.didispace.com/spring-cloud-tips-4/)
65+
- [Spring Cloud实战小贴士:Feign的继承特性(伪RPC模式)](http://blog.didispace.com/spring-cloud-tips-feign-rpc/)
6366
- 未完待续
6467

6568
### 其他文章

0 commit comments

Comments
 (0)