声明式REST客户端-Feign的高级特性
This commit is contained in:
67
spring-cloud-12-api/pom.xml
Normal file
67
spring-cloud-12-api/pom.xml
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?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.roncoo.education</groupId>
|
||||||
|
<artifactId>spring-cloud-12-api</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>spring-cloud-12-api</name>
|
||||||
|
<description>spring-cloud project for Spring Boot</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>1.5.2.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>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.roncoo.education</groupId>
|
||||||
|
<artifactId>spring-cloud-12-bean</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-feign</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
|
<version>Camden.SR6</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.roncoo.education.feign;
|
||||||
|
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wujing
|
||||||
|
*/
|
||||||
|
@FeignClient(value = "roncoo", url = "www.roncoo.com")
|
||||||
|
public interface IRoncooBiz {
|
||||||
|
|
||||||
|
@RequestMapping(value = "/{url}", method = RequestMethod.GET)
|
||||||
|
String get(@PathVariable(name = "url") String url);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.roncoo.education.feign;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import com.roncoo.education.bean.User;
|
||||||
|
import com.roncoo.education.bean.service.UserService;
|
||||||
|
import com.roncoo.education.feign.configuration.RcFeignConfiguration;
|
||||||
|
|
||||||
|
import feign.Param;
|
||||||
|
import feign.RequestLine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wujing
|
||||||
|
*/
|
||||||
|
@FeignClient(value = "spring-cloud-provider", configuration = RcFeignConfiguration.class)
|
||||||
|
public interface IUserBiz extends UserService{
|
||||||
|
|
||||||
|
@RequestMapping(value = "/api/user/{id}", method = RequestMethod.GET)
|
||||||
|
String view1(@PathVariable(name = "id") int id);
|
||||||
|
//说明:method需要指定
|
||||||
|
|
||||||
|
//@RequestLine("GET /api/user/{id}")
|
||||||
|
//String view1(@Param(value = "id") int id);
|
||||||
|
|
||||||
|
//@GetMapping(value = "/api/user/{id}")
|
||||||
|
//String view1(@PathVariable(name = "id") int id);
|
||||||
|
|
||||||
|
|
||||||
|
// 不支持该方式传值,启动出错。
|
||||||
|
//@RequestMapping(value = "/api/user/get/{id}", method = RequestMethod.GET)
|
||||||
|
//User get3(@PathVariable(value = "id") int id, @RequestParam String name);
|
||||||
|
|
||||||
|
/*@RequestMapping(value = "/api/user/get/{id}", method = RequestMethod.GET)
|
||||||
|
User get4(@PathVariable(value = "id") int id, @RequestParam Map<String, Object> name);
|
||||||
|
|
||||||
|
@RequestMapping(value = "/api/user/get/{id}", method = RequestMethod.GET)
|
||||||
|
User get5(@PathVariable(value = "id") int id, @RequestParam(value = "name") String name);
|
||||||
|
|
||||||
|
@RequestMapping(value = "/api/user/get/{id}", method = RequestMethod.GET)
|
||||||
|
User get1(@PathVariable(value = "id") int id, String name);
|
||||||
|
|
||||||
|
@RequestMapping(value = "/api/user/get/{id}", method = RequestMethod.GET)
|
||||||
|
User get2(@PathVariable(value = "id") int id, Map<String, Object> name);
|
||||||
|
|
||||||
|
@RequestMapping(value = "/api/user/{id}", method = RequestMethod.GET)
|
||||||
|
User view(@PathVariable(value = "id") int id);
|
||||||
|
|
||||||
|
//@RequestMapping(value = "/api/user/{id}", method = RequestMethod.GET)
|
||||||
|
//String view1(@PathVariable(value = "id") int id);
|
||||||
|
|
||||||
|
@RequestMapping(value = "/api/user/{id}", method = RequestMethod.GET)
|
||||||
|
Map<String, Object> view2(@PathVariable(value = "id") int id);*/
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.roncoo.education.feign.configuration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import feign.Contract;
|
||||||
|
import feign.Logger;
|
||||||
|
|
||||||
|
//@Configuration
|
||||||
|
public class RcFeignConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Logger.Level feignLoggerLevel() {
|
||||||
|
return feign.Logger.Level.FULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@Bean
|
||||||
|
public Contract feignContract() {
|
||||||
|
return new feign.Contract.Default();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.roncoo.education;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class SpringCloud11ApiApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
34
spring-cloud-12-bean/pom.xml
Normal file
34
spring-cloud-12-bean/pom.xml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?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.roncoo.education</groupId>
|
||||||
|
<artifactId>spring-cloud-12-bean</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>spring-cloud-12-bean</name>
|
||||||
|
<description>spring-cloud project for Spring Boot</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>1.5.2.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>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.roncoo.education.bean;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实体类
|
||||||
|
*
|
||||||
|
* @author wujing
|
||||||
|
*/
|
||||||
|
public class User {
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RoncooUser [id=" + id + ", name=" + name + ", createTime=" + createTime + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.roncoo.education.bean.service;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
import com.roncoo.education.bean.User;
|
||||||
|
|
||||||
|
public interface UserService {
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = "/api/user/find/{id}")
|
||||||
|
User find(@PathVariable(value = "id") int id);
|
||||||
|
}
|
||||||
95
spring-cloud-12-consumer/pom.xml
Normal file
95
spring-cloud-12-consumer/pom.xml
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?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.roncoo.education</groupId>
|
||||||
|
<artifactId>spring-cloud-12-consumer</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>spring-cloud-12-consumer</name>
|
||||||
|
<description>spring-cloud project for Spring Boot</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>1.5.2.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>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-eureka</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.roncoo.education</groupId>
|
||||||
|
<artifactId>spring-cloud-12-api</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
|
<version>Camden.SR6</version>
|
||||||
|
<!-- <version>Dalston.BUILD-SNAPSHOT</version> -->
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>https://repo.spring.io/snapshot</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.roncoo.education;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||||
|
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||||
|
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
@EnableFeignClients
|
||||||
|
@EnableEurekaClient
|
||||||
|
@SpringBootApplication
|
||||||
|
public class ConsumerApplication {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@LoadBalanced
|
||||||
|
protected RestTemplate restTemplate() {
|
||||||
|
return new RestTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ConsumerApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
//package com.roncoo.education.configuration;
|
||||||
|
//import org.springframework.cloud.netflix.ribbon.RibbonClient;
|
||||||
|
//import org.springframework.context.annotation.Configuration;
|
||||||
|
//
|
||||||
|
//@Configuration
|
||||||
|
//@RibbonClient(name = "spring-cloud-provider2", configuration = RoundRobinRuleConfig.class)
|
||||||
|
//public class Provider2Configuration {
|
||||||
|
//
|
||||||
|
//}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
//package com.roncoo.education.configuration;
|
||||||
|
//
|
||||||
|
//import org.springframework.cloud.netflix.ribbon.RibbonClient;
|
||||||
|
//import org.springframework.context.annotation.Configuration;
|
||||||
|
//
|
||||||
|
//@Configuration
|
||||||
|
//@RibbonClient(name = "spring-cloud-provider", configuration = RandomRuleConfig.class)
|
||||||
|
//public class ProviderConfiguration {
|
||||||
|
//
|
||||||
|
//}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
//package com.roncoo.education.configuration;
|
||||||
|
//import org.springframework.context.annotation.Bean;
|
||||||
|
//import org.springframework.context.annotation.Configuration;
|
||||||
|
//import com.netflix.loadbalancer.IRule;
|
||||||
|
//import com.netflix.loadbalancer.RandomRule;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * 随机算法
|
||||||
|
// *
|
||||||
|
// * @author wujing
|
||||||
|
// */
|
||||||
|
////@Configuration
|
||||||
|
//public class RandomRuleConfig {
|
||||||
|
// @Bean
|
||||||
|
// public IRule randomRule() {
|
||||||
|
// return new RandomRule();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package com.roncoo.education.configuration;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.netflix.client.config.IClientConfig;
|
||||||
|
import com.netflix.loadbalancer.AbstractLoadBalancerRule;
|
||||||
|
import com.netflix.loadbalancer.ILoadBalancer;
|
||||||
|
import com.netflix.loadbalancer.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义Ribbon的负载均衡策略
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoncooCustomRule extends AbstractLoadBalancerRule {
|
||||||
|
|
||||||
|
private Server choose(ILoadBalancer lb, Object key) {
|
||||||
|
if (lb == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Server server = null;
|
||||||
|
|
||||||
|
while (server == null) {
|
||||||
|
if (Thread.interrupted()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Server> upList = lb.getReachableServers(); // 可用的服务实例
|
||||||
|
|
||||||
|
// 只获取端口为:7779的服务实例
|
||||||
|
for (Server s : upList) {
|
||||||
|
if (s.getPort() == 7779) {
|
||||||
|
server = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server == null) {
|
||||||
|
Thread.yield();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("实例IP:" + server.getHost() + " 端口:" + server.getPort());
|
||||||
|
|
||||||
|
if (server.isAlive()) {
|
||||||
|
return (server);
|
||||||
|
}
|
||||||
|
|
||||||
|
server = null;
|
||||||
|
Thread.yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Server choose(Object key) {
|
||||||
|
return choose(getLoadBalancer(), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initWithNiwsConfig(IClientConfig clientConfig) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
//package com.roncoo.education.configuration;
|
||||||
|
//import org.springframework.context.annotation.Bean;
|
||||||
|
//import com.netflix.loadbalancer.IRule;
|
||||||
|
//import com.netflix.loadbalancer.RandomRule;
|
||||||
|
//import com.netflix.loadbalancer.RoundRobinRule;
|
||||||
|
///**
|
||||||
|
// * 轮询算法
|
||||||
|
// *
|
||||||
|
// * @author wujing
|
||||||
|
// */
|
||||||
|
//// @Configuration
|
||||||
|
//public class RoundRobinRuleConfig {
|
||||||
|
// @Bean
|
||||||
|
// public IRule roundRobinRule() {
|
||||||
|
// return new RandomRule();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.roncoo.education.controller;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.roncoo.education.bean.User;
|
||||||
|
import com.roncoo.education.feign.IRoncooBiz;
|
||||||
|
import com.roncoo.education.feign.IUserBiz;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wujing
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "/feign/user", method = RequestMethod.POST)
|
||||||
|
public class FeignUserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IUserBiz userBiz;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IRoncooBiz roncooBiz;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||||
|
public String get(@PathVariable(value = "id") int id) {
|
||||||
|
//System.out.println(userBiz.view(id));
|
||||||
|
//System.out.println(userBiz.view1(id));
|
||||||
|
//System.out.println(userBiz.view2(id));
|
||||||
|
|
||||||
|
//String name = "测试1";
|
||||||
|
//Map<String, Object> map = new HashMap<>();
|
||||||
|
//map.put("name", "测试2");
|
||||||
|
//userBiz.get4(id, map);
|
||||||
|
//userBiz.get5(id, name);
|
||||||
|
System.out.println(roncooBiz.get("course/list.html"));
|
||||||
|
System.out.println(userBiz.find(id));
|
||||||
|
return userBiz.view1(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
package com.roncoo.education.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wujing
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "/user", method = RequestMethod.POST)
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
//private static final String URL="http://localhost:7777/api/user/{id}";
|
||||||
|
private static final String URL="http://spring-cloud-provider/api/user/{id}";
|
||||||
|
private static final String URL2="http://spring-cloud-provider2/api/user/{id}";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||||
|
public String get(@PathVariable(value = "id") int id) {
|
||||||
|
return restTemplate.getForObject(URL, String.class, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/2/{id}", method = RequestMethod.GET)
|
||||||
|
public String get2(@PathVariable(value = "id") int id) {
|
||||||
|
return restTemplate.getForObject(URL2, String.class, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
# server
|
||||||
|
server.port=8888
|
||||||
|
|
||||||
|
# spring
|
||||||
|
spring.application.name=spring-cloud-consumer
|
||||||
|
|
||||||
|
# eureka
|
||||||
|
#eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
|
||||||
|
eureka.client.serviceUrl.defaultZone=http://roncoo:123456@localhost:8761/eureka/
|
||||||
|
|
||||||
|
# info自定义
|
||||||
|
info.build.name=@project.name@
|
||||||
|
info.build.description=@project.description@
|
||||||
|
info.build.groupId=@project.groupId@
|
||||||
|
info.build.artifact=@project.artifactId@
|
||||||
|
info.build.version=@project.version@
|
||||||
|
|
||||||
|
eureka.instance.status-page-url-path=/info
|
||||||
|
eureka.instance.instanceId=${spring.application.name}:${random.value}
|
||||||
|
eureka.instance.prefer-ip-address=true
|
||||||
|
|
||||||
|
#设置拉取服务注册信息时间,默认60s
|
||||||
|
eureka.client.registry-fetch-interval-seconds=30
|
||||||
|
|
||||||
|
#指定续约更新频率,默认是30s
|
||||||
|
eureka.instance.lease-renewal-interval-in-seconds=15
|
||||||
|
|
||||||
|
#设置过期剔除时间,默认90s
|
||||||
|
eureka.instance.lease-expiration-duration-in-seconds=45
|
||||||
|
|
||||||
|
#设置策略
|
||||||
|
spring-cloud-provider.ribbon.NFLoadBalancerRuleClassName=com.netflix.loadbalancer.RandomRule
|
||||||
|
spring-cloud-provider2.ribbon.NFLoadBalancerRuleClassName=com.netflix.loadbalancer.RandomRule
|
||||||
|
#spring-cloud-provider.ribbon.NFLoadBalancerRuleClassName=com.roncoo.education.configuration.RoncooCustomRule
|
||||||
|
#格式为:应用名.ribbon.NFLoadBalancerRuleClassName=xxx
|
||||||
|
|
||||||
|
# 日志配置,默认是不打印任何的日志
|
||||||
|
logging.level.com.roncoo.education.feign=debug
|
||||||
|
|
||||||
|
# 开启压缩
|
||||||
|
feign.compression.request.enabled=true
|
||||||
|
feign.compression.response.enabled=true
|
||||||
|
# 更多配置
|
||||||
|
feign.compression.request.mime-types=text/xml,application/xml,application/json
|
||||||
|
feign.compression.request.min-request-size=2048
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.roncoo.education;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class ConsumerApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
94
spring-cloud-12-provider-01/pom.xml
Normal file
94
spring-cloud-12-provider-01/pom.xml
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<?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.roncoo.education</groupId>
|
||||||
|
<artifactId>spring-cloud-12-provider-01</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>spring-cloud-12-provider-01</name>
|
||||||
|
<description>spring-cloud project for Spring Boot</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>1.5.2.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>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.roncoo.education</groupId>
|
||||||
|
<artifactId>spring-cloud-12-bean</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-eureka</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
|
<version>Camden.SR6</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>https://repo.spring.io/snapshot</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.roncoo.education;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||||
|
|
||||||
|
@EnableEurekaClient
|
||||||
|
@SpringBootApplication
|
||||||
|
public class ProviderApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ProviderApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.roncoo.education.controller;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
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;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.roncoo.education.bean.User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wujing
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "/api/user")
|
||||||
|
public class ApiUserController {
|
||||||
|
|
||||||
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
@RequestMapping(value = "/get/{id}")
|
||||||
|
public User get(@PathVariable int id, @RequestBody(required = false) String json, @RequestParam(required = false) String name, HttpServletRequest request) {
|
||||||
|
logger.info("请求方法类型:" + request.getMethod() + " RequestBody参数:" + json + " RequestParam参数:" + name);
|
||||||
|
User user = new User();
|
||||||
|
user.setId(id);
|
||||||
|
user.setName("无境");
|
||||||
|
user.setCreateTime(new Date());
|
||||||
|
// logger.info("请求接口返回:{}", user);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||||
|
public User view(@PathVariable int id) {
|
||||||
|
User user = new User();
|
||||||
|
user.setId(id);
|
||||||
|
user.setName("无境1");
|
||||||
|
user.setCreateTime(new Date());
|
||||||
|
logger.info("请求接口返回:{}", user);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.roncoo.education.controller;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
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;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.roncoo.education.bean.User;
|
||||||
|
import com.roncoo.education.bean.service.UserService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wujing
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
//@RequestMapping(value = "/api/user")
|
||||||
|
public class FeignApiUserController implements UserService {
|
||||||
|
|
||||||
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User find(@PathVariable int id) {
|
||||||
|
User user = new User();
|
||||||
|
user.setId(id);
|
||||||
|
user.setName("无境1");
|
||||||
|
user.setCreateTime(new Date());
|
||||||
|
logger.info("请求接口返回:{}", user);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# server
|
||||||
|
server.port=7778
|
||||||
|
|
||||||
|
# spring
|
||||||
|
spring.application.name=spring-cloud-provider
|
||||||
|
|
||||||
|
# eureka
|
||||||
|
#eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
|
||||||
|
eureka.client.serviceUrl.defaultZone=http://roncoo:123456@roncoo1:8761/eureka/
|
||||||
|
|
||||||
|
# info自定义
|
||||||
|
info.build.name=@project.name@
|
||||||
|
info.build.description=@project.description@
|
||||||
|
info.build.groupId=@project.groupId@
|
||||||
|
info.build.artifact=@project.artifactId@
|
||||||
|
info.build.version=@project.version@
|
||||||
|
|
||||||
|
eureka.instance.status-page-url-path=/info
|
||||||
|
eureka.instance.instanceId=${spring.application.name}:${random.value}
|
||||||
|
eureka.instance.prefer-ip-address=true
|
||||||
|
|
||||||
|
#设置拉取服务注册信息时间,默认60s
|
||||||
|
eureka.client.registry-fetch-interval-seconds=30
|
||||||
|
|
||||||
|
#指定续约更新频率,默认是30s
|
||||||
|
eureka.instance.lease-renewal-interval-in-seconds=15
|
||||||
|
|
||||||
|
#设置过期剔除时间,默认90s
|
||||||
|
eureka.instance.lease-expiration-duration-in-seconds=45
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.roncoo.education;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class ProviderApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
89
spring-cloud-12-service/pom.xml
Normal file
89
spring-cloud-12-service/pom.xml
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
<?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.roncoo.education</groupId>
|
||||||
|
<artifactId>spring-cloud-12-service</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>spring-cloud-12-service</name>
|
||||||
|
<description>spring-cloud project for Spring Boot</description>
|
||||||
|
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>1.5.2.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>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
|
<version>Camden.SR6</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>https://repo.spring.io/snapshot</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.roncoo.education;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
|
||||||
|
|
||||||
|
@EnableEurekaServer
|
||||||
|
@SpringBootApplication
|
||||||
|
public class ServiceApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# server (eureka 默认端口为:8761)
|
||||||
|
server.port=8761
|
||||||
|
|
||||||
|
# spring
|
||||||
|
spring.application.name=spring-cloud-server
|
||||||
|
|
||||||
|
# eureka
|
||||||
|
# 是否注册到eureka
|
||||||
|
eureka.client.register-with-eureka=false
|
||||||
|
# 是否从eureka获取注册信息
|
||||||
|
eureka.client.fetch-registry=false
|
||||||
|
# eureka服务器的地址(注意:地址最后面的 /eureka/ 这个是固定值)
|
||||||
|
#eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
|
||||||
|
eureka.client.serviceUrl.defaultZone=http://roncoo:123456@localhost:8761/eureka/
|
||||||
|
eureka.client.availability-zones.roncoo=roncooZone
|
||||||
|
eureka.client.service-url.roncooZone=http://roncoo:123456@localhost:8761/eureka/
|
||||||
|
eureka.client.region=lll
|
||||||
|
|
||||||
|
|
||||||
|
# info自定义
|
||||||
|
info.build.name=@project.name@
|
||||||
|
info.build.description=@project.description@
|
||||||
|
info.build.groupId=@project.groupId@
|
||||||
|
info.build.artifact=@project.artifactId@
|
||||||
|
info.build.version=@project.version@
|
||||||
|
|
||||||
|
# 指定环境
|
||||||
|
eureka.environment=dev
|
||||||
|
|
||||||
|
#指定数据中心
|
||||||
|
eureka.datacenter=roncoo
|
||||||
|
|
||||||
|
# 关闭自我保护模式
|
||||||
|
eureka.server.enable-self-preservation=false
|
||||||
|
|
||||||
|
#设置清理无效节点的时间间隔,默认60000,即是60s
|
||||||
|
eureka.server.eviction-interval-timer-in-ms=5000
|
||||||
|
|
||||||
|
# 服务认证
|
||||||
|
security.basic.enabled=true
|
||||||
|
security.user.name=roncoo
|
||||||
|
security.user.password=123456
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.roncoo.education;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class ServiceApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user