forked from wuyouzhuguli/SpringAll
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
43d4c9c
commit a58e9b7
Showing
18 changed files
with
615 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
33.Spring-Cloud-Feign-Declarative-REST-Client/Eureka-Client/pom.xml
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,60 @@ | ||
<?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>com.example</groupId> | ||
<artifactId>Eureka-Client</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Eureka-Client</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.5.13.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>Edgware.SR3</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-eureka</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
15 changes: 15 additions & 0 deletions
15
...Declarative-REST-Client/Eureka-Client/src/main/java/com/example/demo/DemoApplication.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 com.example.demo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
|
||
@EnableDiscoveryClient | ||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) | ||
public class DemoApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DemoApplication.class, args); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...e-REST-Client/Eureka-Client/src/main/java/com/example/demo/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,32 @@ | ||
package com.example.demo.controller; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.cloud.client.ServiceInstance; | ||
import org.springframework.cloud.client.discovery.DiscoveryClient; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class TestController { | ||
|
||
private Logger log = LoggerFactory.getLogger(this.getClass()); | ||
|
||
@Autowired | ||
private DiscoveryClient client; | ||
|
||
@GetMapping("/info") | ||
public String info() { | ||
@SuppressWarnings("deprecation") | ||
ServiceInstance instance = client.getLocalServiceInstance(); | ||
String info = "host:" + instance.getHost() + ",service_id:" + instance.getServiceId(); | ||
log.info(info); | ||
return info; | ||
} | ||
|
||
@GetMapping("/hello") | ||
public String hello() { | ||
return "hello world"; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...e-REST-Client/Eureka-Client/src/main/java/com/example/demo/controller/UserController.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,47 @@ | ||
package com.example.demo.controller; | ||
|
||
import com.example.demo.domain.User; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("user") | ||
public class UserController { | ||
|
||
private Logger log = LoggerFactory.getLogger(this.getClass()); | ||
|
||
@GetMapping("/{id:\\d+}") | ||
public User get(@PathVariable Long id) { | ||
log.info("获取用户id为 " + id + "的信息"); | ||
return new User(id, "mrbird", "123456"); | ||
} | ||
|
||
@GetMapping | ||
public List<User> get() { | ||
List<User> list = new ArrayList<>(); | ||
list.add(new User(1L, "mrbird", "123456")); | ||
list.add(new User(2L, "scott", "123456")); | ||
log.info("获取用户信息 " + list); | ||
return list; | ||
} | ||
|
||
@PostMapping | ||
public void add(@RequestBody User user) { | ||
log.info("新增用户成功 " + user); | ||
} | ||
|
||
@PutMapping | ||
public void update(@RequestBody User user) { | ||
log.info("更新用户成功 " + user); | ||
} | ||
|
||
@DeleteMapping("/{id:\\d+}") | ||
public void delete(@PathVariable Long id) { | ||
log.info("删除用户成功 " + id); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...ign-Declarative-REST-Client/Eureka-Client/src/main/java/com/example/demo/domain/User.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,55 @@ | ||
package com.example.demo.domain; | ||
|
||
import java.io.Serializable; | ||
|
||
public class User implements Serializable { | ||
|
||
private static final long serialVersionUID = 1339434510787399891L; | ||
private Long id; | ||
|
||
private String username; | ||
|
||
private String password; | ||
|
||
public User() { | ||
} | ||
|
||
public User(Long id, String username, String password) { | ||
this.id = id; | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "User{" + | ||
"id=" + id + | ||
", username='" + username + '\'' + | ||
", password='" + password + '\'' + | ||
'}'; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ring-Cloud-Feign-Declarative-REST-Client/Eureka-Client/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: 8082 | ||
|
||
spring: | ||
application: | ||
name: Server-Provider | ||
|
||
eureka: | ||
client: | ||
register-with-eureka: true | ||
fetch-registry: true | ||
serviceUrl: | ||
defaultZone: http://mrbird:123456@peer1:8080/eureka/,http://mrbird:123456@peer2:8081/eureka/ |
69 changes: 69 additions & 0 deletions
69
33.Spring-Cloud-Feign-Declarative-REST-Client/Eureka-Service/pom.xml
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>com.example</groupId> | ||
<artifactId>Eureka-Service</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Eureka-Service</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.5.13.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>Edgware.SR3</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-eureka-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-security</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>nexus-aliyun</id> | ||
<name>Nexus aliyun</name> | ||
<url>http://maven.aliyun.com/nexus/content/groups/public</url> | ||
</repository> | ||
</repositories> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
14 changes: 14 additions & 0 deletions
14
...eclarative-REST-Client/Eureka-Service/src/main/java/com/example/demo/DemoApplication.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,14 @@ | ||
package com.example.demo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; | ||
|
||
|
||
@EnableEurekaServer | ||
@SpringBootApplication | ||
public class DemoApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(DemoApplication.class, args); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...oud-Feign-Declarative-REST-Client/Eureka-Service/src/main/resources/application-peer1.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,15 @@ | ||
server: | ||
port: 8080 | ||
|
||
spring: | ||
application: | ||
name: Eureka-Server | ||
|
||
eureka: | ||
instance: | ||
hostname: peer1 | ||
client: | ||
serviceUrl: | ||
defaultZone: http://mrbird:123456@peer2:8081/eureka/ | ||
server: | ||
enable-self-preservation: false |
15 changes: 15 additions & 0 deletions
15
...oud-Feign-Declarative-REST-Client/Eureka-Service/src/main/resources/application-peer2.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,15 @@ | ||
server: | ||
port: 8081 | ||
|
||
spring: | ||
application: | ||
name: Eureka-Server | ||
|
||
eureka: | ||
instance: | ||
hostname: peer2 | ||
client: | ||
serviceUrl: | ||
defaultZone: http://mrbird:123456@peer1:8080/eureka/ | ||
server: | ||
enable-self-preservation: false |
9 changes: 9 additions & 0 deletions
9
...ing-Cloud-Feign-Declarative-REST-Client/Eureka-Service/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,9 @@ | ||
security: | ||
basic: | ||
enabled: true | ||
user: | ||
name: mrbird | ||
password: 123456 | ||
spring: | ||
profiles: | ||
active: peer1 |
Oops, something went wrong.