-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
646 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.ken.springcloud.eurekaserver</groupId> | ||
<artifactId>eurekaserver</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>eurekaserver</name> | ||
<url>http://ken.io</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.0.0.RELEASE</version> | ||
</parent> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>Finchley.BUILD-SNAPSHOT</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spring-snapshots</id> | ||
<name>Spring Snapshots</name> | ||
<url>https://repo.spring.io/libs-snapshot</url> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<build> | ||
<finalName>eurekaserver</finalName> | ||
</build> | ||
|
||
</project> |
15 changes: 15 additions & 0 deletions
15
chapter-03/eurekaserver/src/main/java/io/ken/springcloud/eurekaserver/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.ken.springcloud.eurekaserver; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; | ||
|
||
|
||
@EnableEurekaServer | ||
@SpringBootApplication | ||
public class App { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(App.class, args); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
chapter-03/eurekaserver/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
server: | ||
port: 8800 | ||
|
||
spring: | ||
application: | ||
name: EurekaServer | ||
|
||
eureka: | ||
client: | ||
registerWithEureka: false | ||
fetchRegistry: false | ||
serviceUrl: | ||
defaultZone: http://localhost:${server.port}/eureka/ |
20 changes: 20 additions & 0 deletions
20
chapter-03/eurekaserver/src/test/java/io/ken/springcloud/eurekaserver/AppTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.ken.springcloud.eurekaserver; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Unit test for simple App. | ||
*/ | ||
public class AppTest | ||
{ | ||
/** | ||
* Rigorous Test :-) | ||
*/ | ||
@Test | ||
public void shouldAnswerWithTrue() | ||
{ | ||
assertTrue( true ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.ken.springcloud.feignclient</groupId> | ||
<artifactId>feignclient</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>feignclient</name> | ||
<url>http://ken.io</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.0.0.RELEASE</version> | ||
</parent> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>Finchley.BUILD-SNAPSHOT</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-openfeign</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spring-snapshots</id> | ||
<name>Spring Snapshots</name> | ||
<url>https://repo.spring.io/libs-snapshot</url> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<build> | ||
<finalName>feignclient</finalName> | ||
</build> | ||
|
||
</project> |
17 changes: 17 additions & 0 deletions
17
chapter-03/feignclient/src/main/java/io/ken/springcloud/feignclient/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.ken.springcloud.feignclient; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
|
||
@EnableFeignClients | ||
@EnableDiscoveryClient | ||
@SpringBootApplication | ||
public class App { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(App.class, args); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...3/feignclient/src/main/java/io/ken/springcloud/feignclient/controller/TestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.ken.springcloud.feignclient.controller; | ||
|
||
import io.ken.springcloud.feignclient.model.Plus; | ||
import io.ken.springcloud.feignclient.service.TestService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class TestController { | ||
|
||
@Autowired | ||
private TestService testService; | ||
|
||
@RequestMapping("/") | ||
public Object index() { | ||
return "feign client"; | ||
} | ||
|
||
@RequestMapping("/ti") | ||
public Object ti() { | ||
return testService.indexService(); | ||
} | ||
|
||
@RequestMapping("/plus") | ||
public Object plus(@RequestParam("numa") int numA, @RequestParam("numb") int numB) { | ||
return testService.plusService(numA, numB); | ||
} | ||
|
||
@RequestMapping("/plusab") | ||
public Object plusA(@RequestParam("numa") int numA, @RequestParam("numb") int numB) { | ||
Plus plus = new Plus(); | ||
plus.setNumA(numA); | ||
plus.setNumB(numB); | ||
return testService.plusabService(plus); | ||
} | ||
|
||
@RequestMapping("/plus2") | ||
public Object plus2(Plus plus) { | ||
return testService.plus2Service(plus); | ||
} | ||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
chapter-03/feignclient/src/main/java/io/ken/springcloud/feignclient/model/Plus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.ken.springcloud.feignclient.model; | ||
|
||
public class Plus { | ||
|
||
private int numA; | ||
|
||
private int numB; | ||
|
||
public int getNumA() { | ||
return numA; | ||
} | ||
|
||
public void setNumA(int numA) { | ||
this.numA = numA; | ||
} | ||
|
||
public int getNumB() { | ||
return numB; | ||
} | ||
|
||
public void setNumB(int numB) { | ||
this.numB = numB; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
chapter-03/feignclient/src/main/java/io/ken/springcloud/feignclient/model/Result.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.ken.springcloud.feignclient.model; | ||
|
||
public class Result { | ||
|
||
private int code; | ||
|
||
private String message; | ||
|
||
private Object content; | ||
|
||
private String serviceName; | ||
|
||
private String host; | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(int code) { | ||
this.code = code; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public Object getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(Object content) { | ||
this.content = content; | ||
} | ||
|
||
public String getServiceName() { | ||
return serviceName; | ||
} | ||
|
||
public void setServiceName(String serviceName) { | ||
this.serviceName = serviceName; | ||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
public void setHost(String host) { | ||
this.host = host; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
chapter-03/feignclient/src/main/java/io/ken/springcloud/feignclient/service/TestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.ken.springcloud.feignclient.service; | ||
|
||
import io.ken.springcloud.feignclient.model.Plus; | ||
import io.ken.springcloud.feignclient.model.Result; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@FeignClient(value = "testservice") | ||
public interface TestService { | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
String indexService(); | ||
|
||
@RequestMapping(value = "/plus", method = RequestMethod.GET) | ||
Result plusService(@RequestParam(name = "numA") int numA, @RequestParam(name = "numB") int numB); | ||
|
||
@RequestMapping(value = "/plus", method = RequestMethod.POST, consumes = "application/json") | ||
Result plusabService(Plus plus); | ||
|
||
@RequestMapping(value = "/plus2", method = RequestMethod.POST) | ||
Result plus2Service(@RequestBody Plus plus); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
server: | ||
port: 8605 | ||
|
||
spring: | ||
application: | ||
name: feignclient | ||
|
||
eureka: | ||
client: | ||
serviceUrl: | ||
defaultZone: http://localhost:8800/eureka/ |
Oops, something went wrong.