From 42360bfcb0fe1019d5f369a46a71d6c8d372ee0c Mon Sep 17 00:00:00 2001 From: williamjava Date: Thu, 27 Dec 2018 14:04:03 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96develop?= =?UTF-8?q?=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star-eureka-server/target/classes/application.yml | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 star-eureka-server/target/classes/application.yml diff --git a/star-eureka-server/target/classes/application.yml b/star-eureka-server/target/classes/application.yml deleted file mode 100644 index 1127543..0000000 --- a/star-eureka-server/target/classes/application.yml +++ /dev/null @@ -1,4 +0,0 @@ -##使用yml配置文件时,读取属性值必须使用@@的方式 -spring: - profiles: - active: 'dev' \ No newline at end of file From 3749e76f3667427c841360e87d9df30138a0cacd Mon Sep 17 00:00:00 2001 From: williamjava Date: Thu, 27 Dec 2018 14:29:32 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E5=8D=87=E7=BA=A7springboot=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star-eureka-server/.classpath | 2 +- star-eureka-server/.gitignore | 6 +++++- .../.settings/org.eclipse.jdt.core.prefs | 6 +++--- star-eureka-server/pom.xml | 8 +++----- .../star_eureka_server/EurekaApplication.java | 1 + .../src/main/resources/application-dev.yml | 17 +++++++---------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/star-eureka-server/.classpath b/star-eureka-server/.classpath index e580d60..078648f 100644 --- a/star-eureka-server/.classpath +++ b/star-eureka-server/.classpath @@ -19,7 +19,7 @@ - + diff --git a/star-eureka-server/.gitignore b/star-eureka-server/.gitignore index b83d222..4782c17 100644 --- a/star-eureka-server/.gitignore +++ b/star-eureka-server/.gitignore @@ -1 +1,5 @@ -/target/ +.classpath +.project +.settings/ +target/ +bin/ diff --git a/star-eureka-server/.settings/org.eclipse.jdt.core.prefs b/star-eureka-server/.settings/org.eclipse.jdt.core.prefs index 60105c1..714351a 100644 --- a/star-eureka-server/.settings/org.eclipse.jdt.core.prefs +++ b/star-eureka-server/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/star-eureka-server/pom.xml b/star-eureka-server/pom.xml index 5dc45d5..81d6f5e 100644 --- a/star-eureka-server/pom.xml +++ b/star-eureka-server/pom.xml @@ -20,7 +20,7 @@ org.springframework.boot spring-boot-starter-parent - 1.4.3.RELEASE + 2.0.5.RELEASE @@ -38,10 +38,9 @@ org.springframework.cloud - spring-cloud-starter-eureka-server + spring-cloud-starter-netflix-eureka-server - junit junit @@ -55,7 +54,7 @@ org.springframework.cloud spring-cloud-dependencies - Camden.SR4 + Finchley.RELEASE pom import @@ -105,7 +104,6 @@ 指定资源,这里是我们生成的jar,将用于启动到容器 / ${project.build.directory} ${project.build.finalName}.jar --> - diff --git a/star-eureka-server/src/main/java/com/gui/star_eureka_server/EurekaApplication.java b/star-eureka-server/src/main/java/com/gui/star_eureka_server/EurekaApplication.java index 171d857..8e91843 100644 --- a/star-eureka-server/src/main/java/com/gui/star_eureka_server/EurekaApplication.java +++ b/star-eureka-server/src/main/java/com/gui/star_eureka_server/EurekaApplication.java @@ -22,6 +22,7 @@ public class EurekaApplication { public static void main(String[] args) { SpringApplication.run(EurekaApplication.class, args); + // SpringApplication.run(EurekaApplication.class, // "spring.profiles.active=peer1"); } diff --git a/star-eureka-server/src/main/resources/application-dev.yml b/star-eureka-server/src/main/resources/application-dev.yml index 3f641ca..d31effc 100755 --- a/star-eureka-server/src/main/resources/application-dev.yml +++ b/star-eureka-server/src/main/resources/application-dev.yml @@ -1,6 +1,12 @@ spring: application: name: star-eureka-server + ###为我们的Eureka服务注册和发现中心添加用户认证 + ###添加之后,对应的所有服务提供者和服务消费者,访问的eureka地址都需要做出对应的变更,如:http://william:123456@127.0.0.1:1314/eureka/ + security: + user: + name: william + password: 123456 ###在默认设置下,该服务注册中心也会将自己作为客户端来尝试注册它自己,所以我们需要禁用它的客户端注册行为 server: @@ -13,13 +19,4 @@ eureka: serviceUrl: defaultZone: http://localhost:1314/eureka/ server: - enableSelfPreservation: false - -###为我们的Eureka服务注册和发现中心添加用户认证 -###添加之后,对应的所有服务提供者和服务消费者,访问的eureka地址都需要做出对应的变更,如:http://william:123456@127.0.0.1:1314/eureka/ -security: - basic: - enabled: true - user: - name: william - password: 123456 \ No newline at end of file + enableSelfPreservation: false \ No newline at end of file From 9d286f4982f920347bd29f59333b41f537e25407 Mon Sep 17 00:00:00 2001 From: williamjava Date: Thu, 27 Dec 2018 16:37:50 +0800 Subject: [PATCH 03/15] =?UTF-8?q?SpringBoot=E7=89=88=E6=9C=AC=E5=8D=87?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star-compute-service/.classpath | 2 +- .../.settings/org.eclipse.jdt.core.prefs | 6 ++-- star-compute-service/pom.xml | 12 ++++---- .../config/RedisConfig.java | 7 ++--- .../controller/ComputeController.java | 19 ++++++++++++- .../controller/RabbitMQTestController.java | 4 --- .../src/main/resources/application.yml | 5 +++- .../src/main/resources/bootstrap.yml | 28 ++++++++----------- 8 files changed, 45 insertions(+), 38 deletions(-) diff --git a/star-compute-service/.classpath b/star-compute-service/.classpath index 6aff346..5d2afd4 100644 --- a/star-compute-service/.classpath +++ b/star-compute-service/.classpath @@ -18,7 +18,7 @@ - + diff --git a/star-compute-service/.settings/org.eclipse.jdt.core.prefs b/star-compute-service/.settings/org.eclipse.jdt.core.prefs index 60105c1..714351a 100644 --- a/star-compute-service/.settings/org.eclipse.jdt.core.prefs +++ b/star-compute-service/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/star-compute-service/pom.xml b/star-compute-service/pom.xml index 937a221..b31a9fb 100644 --- a/star-compute-service/pom.xml +++ b/star-compute-service/pom.xml @@ -17,7 +17,7 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.5.RELEASE @@ -30,19 +30,18 @@ org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-netflix-eureka-client org.springframework.boot spring-boot-starter-data-redis - 2.0.2.RELEASE - redis.clients - jedis + redis.clients + jedis @@ -95,7 +94,6 @@ org.projectlombok lombok - 1.16.6 @@ -120,7 +118,7 @@ org.springframework.cloud spring-cloud-dependencies - Brixton.SR5 + Finchley.RELEASE pom import diff --git a/star-compute-service/src/main/java/com/gui/star_compute_service/config/RedisConfig.java b/star-compute-service/src/main/java/com/gui/star_compute_service/config/RedisConfig.java index 1a2b991..9643a97 100644 --- a/star-compute-service/src/main/java/com/gui/star_compute_service/config/RedisConfig.java +++ b/star-compute-service/src/main/java/com/gui/star_compute_service/config/RedisConfig.java @@ -52,13 +52,10 @@ public Object generate(Object target, Method method, Object... params) { * @param redisTemplate * @return */ - @SuppressWarnings("rawtypes") @Bean - public CacheManager cacheManager(RedisTemplate redisTemplate) { - RedisCacheManager rcm = new RedisCacheManager(redisTemplate); + public CacheManager cacheManager(RedisConnectionFactory factory) { + RedisCacheManager rcm = RedisCacheManager.create(factory); // 设置缓存过期时间 - rcm.setDefaultExpiration(10000); - return rcm; } diff --git a/star-compute-service/src/main/java/com/gui/star_compute_service/controller/ComputeController.java b/star-compute-service/src/main/java/com/gui/star_compute_service/controller/ComputeController.java index 6bf7312..0384f5f 100644 --- a/star-compute-service/src/main/java/com/gui/star_compute_service/controller/ComputeController.java +++ b/star-compute-service/src/main/java/com/gui/star_compute_service/controller/ComputeController.java @@ -1,11 +1,14 @@ package com.gui.star_compute_service.controller; +import java.util.List; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.cloud.client.serviceregistry.Registration; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; @@ -38,6 +41,9 @@ public class ComputeController { @Value("${author.age}") private Integer age; + + @Autowired + private Registration registration; @Autowired private DiscoveryClient client; @@ -57,7 +63,7 @@ public class ComputeController { @ApiImplicitParam(name = "b", value = "第二个数", required = true, dataType = "int", paramType = "query") }) @RequestMapping(value = "/add", method = RequestMethod.GET) public Integer add(@RequestParam Integer a, @RequestParam Integer b) { - ServiceInstance instance = client.getLocalServiceInstance(); + ServiceInstance instance = serviceInstance(); Integer r = a + b; logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r); @@ -84,4 +90,15 @@ public void setName(String name) { public void setAge(Integer age) { this.age = age; } + + public ServiceInstance serviceInstance() { + List list = client.getInstances(registration.getServiceId()); + if (list != null && list.size() > 0) { + for(ServiceInstance itm : list){ + if(itm.getPort() == 2001) + return itm; + } + } + return null; + } } diff --git a/star-compute-service/src/main/java/com/gui/star_compute_service/controller/RabbitMQTestController.java b/star-compute-service/src/main/java/com/gui/star_compute_service/controller/RabbitMQTestController.java index 49f6c70..2a1e74f 100644 --- a/star-compute-service/src/main/java/com/gui/star_compute_service/controller/RabbitMQTestController.java +++ b/star-compute-service/src/main/java/com/gui/star_compute_service/controller/RabbitMQTestController.java @@ -1,16 +1,12 @@ package com.gui.star_compute_service.controller; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.Cacheable; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.gui.star_compute_service.util.RabbitMQUtil; -import com.gui.star_compute_service.util.RedisUtil; -import com.gui.star_compute_service.vo.UserVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; diff --git a/star-compute-service/src/main/resources/application.yml b/star-compute-service/src/main/resources/application.yml index 51b73c7..f4641f9 100755 --- a/star-compute-service/src/main/resources/application.yml +++ b/star-compute-service/src/main/resources/application.yml @@ -2,4 +2,7 @@ ## 设置这些消息是为了测试的时候有个参照,从而确定某个值到底来源于远程的git仓库还是本地保存的值 author: name: WilliamLocal - age: 66 \ No newline at end of file + age: 66 + +server: + port: 5558 \ No newline at end of file diff --git a/star-compute-service/src/main/resources/bootstrap.yml b/star-compute-service/src/main/resources/bootstrap.yml index 94b6a8a..ed4a7f7 100644 --- a/star-compute-service/src/main/resources/bootstrap.yml +++ b/star-compute-service/src/main/resources/bootstrap.yml @@ -5,18 +5,18 @@ #### 注意,最终读取的文件的名字是:name + "-" + profile + ".yml" 文件, 本例中就是读取sample-cloud-client-test.yml文件,这个优先级最高 #### 如果此文件找不到,接着会去找application-test.yml文件,如果这个文件也没有,最后将会从客户端本地读取 spring: -## rabbitmq: -## host: 127.0.0.1 -## port: 5672 -## username: guest -## password: guest + rabbitmq: + host: 127.0.0.1 + port: 5672 + username: guest + password: guest application: name: compute-service - rabbitmq: - host: localhost - port: 5672 - username: guest - password: guest + #rabbitmq: + #host: localhost + #port: 5672 + #username: guest + #password: guest redis: ##Redis数据库索引(默认为0) database: 0 @@ -48,16 +48,12 @@ spring: ## uri: http://127.0.0.1:52099 ## name: sample-cloud-client ## profile: test - -server: - port: 5558 - eureka: client: serviceUrl: - defaultZone: http://william:123456@peer1:1314/eureka/ - ##defaultZone: http://william:123456@localhost:1314/eureka/ + ##defaultZone: http://william:123456@peer1:1314/eureka/ + defaultZone: http:/localhost:1314/eureka/ healthcheck: enabled: true From a4f845e6b00ba853ce330477316dc0f23e87f878 Mon Sep 17 00:00:00 2001 From: williamjava Date: Thu, 27 Dec 2018 16:39:22 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E5=A2=9E=E5=8A=A0git=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star-compute-service/.gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/star-compute-service/.gitignore b/star-compute-service/.gitignore index b83d222..4782c17 100644 --- a/star-compute-service/.gitignore +++ b/star-compute-service/.gitignore @@ -1 +1,5 @@ -/target/ +.classpath +.project +.settings/ +target/ +bin/ From 3c17d288270e93b2c786b44a5d0a54a2a2c9834d Mon Sep 17 00:00:00 2001 From: williamjava Date: Thu, 27 Dec 2018 16:45:53 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E5=A2=9E=E5=8A=A0git=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star-eureka-ribbon/.classpath | 2 +- star-eureka-ribbon/.gitignore | 6 +++++- .../.settings/org.eclipse.jdt.core.prefs | 6 +++--- star-eureka-ribbon/pom.xml | 10 +++++----- star-eureka-ribbon/src/main/resources/application.yml | 3 ++- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/star-eureka-ribbon/.classpath b/star-eureka-ribbon/.classpath index edc9698..9b136af 100644 --- a/star-eureka-ribbon/.classpath +++ b/star-eureka-ribbon/.classpath @@ -17,7 +17,7 @@ - + diff --git a/star-eureka-ribbon/.gitignore b/star-eureka-ribbon/.gitignore index b83d222..4782c17 100644 --- a/star-eureka-ribbon/.gitignore +++ b/star-eureka-ribbon/.gitignore @@ -1 +1,5 @@ -/target/ +.classpath +.project +.settings/ +target/ +bin/ diff --git a/star-eureka-ribbon/.settings/org.eclipse.jdt.core.prefs b/star-eureka-ribbon/.settings/org.eclipse.jdt.core.prefs index 60105c1..714351a 100644 --- a/star-eureka-ribbon/.settings/org.eclipse.jdt.core.prefs +++ b/star-eureka-ribbon/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/star-eureka-ribbon/pom.xml b/star-eureka-ribbon/pom.xml index a6f5644..6baa41e 100644 --- a/star-eureka-ribbon/pom.xml +++ b/star-eureka-ribbon/pom.xml @@ -16,7 +16,7 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.5.RELEASE @@ -24,12 +24,12 @@ org.springframework.cloud - spring-cloud-starter-ribbon + spring-cloud-starter-netflix-ribbon org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-netflix-eureka-client @@ -51,7 +51,7 @@ org.springframework.cloud - spring-cloud-starter-hystrix + spring-cloud-starter-netflix-hystrix @@ -60,7 +60,7 @@ org.springframework.cloud spring-cloud-dependencies - Brixton.RELEASE + Finchley.RELEASE pom import diff --git a/star-eureka-ribbon/src/main/resources/application.yml b/star-eureka-ribbon/src/main/resources/application.yml index cb186e7..6a692cc 100755 --- a/star-eureka-ribbon/src/main/resources/application.yml +++ b/star-eureka-ribbon/src/main/resources/application.yml @@ -8,4 +8,5 @@ server: eureka: client: serviceUrl: - defaultZone: http://william:123456@localhost:1314/eureka/ \ No newline at end of file + #defaultZone: http://william:123456@localhost:1314/eureka/ + defaultZone: http://localhost:1314/eureka/ \ No newline at end of file From 6c2f4f1ede4e25ca2614338a9c49a2a695908d72 Mon Sep 17 00:00:00 2001 From: williamjava Date: Thu, 27 Dec 2018 16:48:20 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star-eureka-server/pom.xml | 4 ++-- star-eureka-server/src/main/resources/application-dev.yml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/star-eureka-server/pom.xml b/star-eureka-server/pom.xml index 81d6f5e..5549d96 100644 --- a/star-eureka-server/pom.xml +++ b/star-eureka-server/pom.xml @@ -31,10 +31,10 @@ test - + org.springframework.cloud diff --git a/star-eureka-server/src/main/resources/application-dev.yml b/star-eureka-server/src/main/resources/application-dev.yml index d31effc..0109d2d 100755 --- a/star-eureka-server/src/main/resources/application-dev.yml +++ b/star-eureka-server/src/main/resources/application-dev.yml @@ -3,10 +3,10 @@ spring: name: star-eureka-server ###为我们的Eureka服务注册和发现中心添加用户认证 ###添加之后,对应的所有服务提供者和服务消费者,访问的eureka地址都需要做出对应的变更,如:http://william:123456@127.0.0.1:1314/eureka/ - security: - user: - name: william - password: 123456 + #security: + #user: + #name: william + #password: 123456 ###在默认设置下,该服务注册中心也会将自己作为客户端来尝试注册它自己,所以我们需要禁用它的客户端注册行为 server: From ac2662f97772997c935cfbf7f1973892ef108560 Mon Sep 17 00:00:00 2001 From: williamjava Date: Thu, 27 Dec 2018 18:52:39 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star-compute-service/pom.xml | 11 +++- .../ComputeServiceApplication.java | 2 +- .../config/RedisConfig.java | 33 +++++----- .../controller/ComputeController.java | 2 +- .../src/main/resources/application.yml | 66 ++++++++++++++++++- .../src/main/resources/bootstrap.yml | 63 ------------------ .../src/main/resources/logback-spring.xml | 6 +- 7 files changed, 95 insertions(+), 88 deletions(-) delete mode 100644 star-compute-service/src/main/resources/bootstrap.yml diff --git a/star-compute-service/pom.xml b/star-compute-service/pom.xml index b31a9fb..34cf325 100644 --- a/star-compute-service/pom.xml +++ b/star-compute-service/pom.xml @@ -57,11 +57,11 @@ - + @@ -78,12 +78,17 @@ - + org.springframework.boot spring-boot-starter-actuator true + + + org.springframework.cloud + spring-cloud-starter-netflix-hystrix + junit diff --git a/star-compute-service/src/main/java/com/gui/star_compute_service/ComputeServiceApplication.java b/star-compute-service/src/main/java/com/gui/star_compute_service/ComputeServiceApplication.java index f9c6429..2ca877b 100644 --- a/star-compute-service/src/main/java/com/gui/star_compute_service/ComputeServiceApplication.java +++ b/star-compute-service/src/main/java/com/gui/star_compute_service/ComputeServiceApplication.java @@ -20,6 +20,6 @@ @SpringBootApplication public class ComputeServiceApplication { public static void main(String[] args) { - SpringApplication.run(ComputeServiceApplication.class, args); + SpringApplication.run(ComputeServiceApplication.class, "--server.port=5559"); } } \ No newline at end of file diff --git a/star-compute-service/src/main/java/com/gui/star_compute_service/config/RedisConfig.java b/star-compute-service/src/main/java/com/gui/star_compute_service/config/RedisConfig.java index 9643a97..12bbc52 100644 --- a/star-compute-service/src/main/java/com/gui/star_compute_service/config/RedisConfig.java +++ b/star-compute-service/src/main/java/com/gui/star_compute_service/config/RedisConfig.java @@ -1,11 +1,8 @@ package com.gui.star_compute_service.config; -import java.lang.reflect.Method; - import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; -import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.cache.RedisCacheManager; @@ -30,21 +27,21 @@ public class RedisConfig extends CachingConfigurerSupport { /** * 自定义key的生成策略 */ - @Bean - public KeyGenerator keyGenerator() { - return new KeyGenerator() { - @Override - public Object generate(Object target, Method method, Object... params) { - StringBuilder sb = new StringBuilder(); - sb.append(target.getClass().getName()); - sb.append(method.getName()); - for (Object obj : params) { - sb.append(obj.toString()); - } - return sb.toString(); - } - }; - } + // @Bean + // public KeyGenerator keyGenerator() { + // return new KeyGenerator() { + // @Override + // public Object generate(Object target, Method method, Object... params) { + // StringBuilder sb = new StringBuilder(); + // sb.append(target.getClass().getName()); + // sb.append(method.getName()); + // for (Object obj : params) { + // sb.append(obj.toString()); + // } + // return sb.toString(); + // } + // }; + // } /** * 缓存管理器 diff --git a/star-compute-service/src/main/java/com/gui/star_compute_service/controller/ComputeController.java b/star-compute-service/src/main/java/com/gui/star_compute_service/controller/ComputeController.java index 0384f5f..fb2d322 100644 --- a/star-compute-service/src/main/java/com/gui/star_compute_service/controller/ComputeController.java +++ b/star-compute-service/src/main/java/com/gui/star_compute_service/controller/ComputeController.java @@ -95,7 +95,7 @@ public ServiceInstance serviceInstance() { List list = client.getInstances(registration.getServiceId()); if (list != null && list.size() > 0) { for(ServiceInstance itm : list){ - if(itm.getPort() == 2001) + if(itm.getPort() == 5558) return itm; } } diff --git a/star-compute-service/src/main/resources/application.yml b/star-compute-service/src/main/resources/application.yml index f4641f9..593ac9f 100755 --- a/star-compute-service/src/main/resources/application.yml +++ b/star-compute-service/src/main/resources/application.yml @@ -4,5 +4,69 @@ author: name: WilliamLocal age: 66 +## uri 这个值一定要和配置服务器保持一致 +## name 指定要从git远程仓库读取哪个文件 +## profile 指定读取文件的哪个版本(比如abc-test.yml 或者 abc-dev.yml文件) +## discovery 服务注册与发现 +#### 注意,最终读取的文件的名字是:name + "-" + profile + ".yml" 文件, 本例中就是读取sample-cloud-client-test.yml文件,这个优先级最高 +#### 如果此文件找不到,接着会去找application-test.yml文件,如果这个文件也没有,最后将会从客户端本地读取 +spring: + rabbitmq: + host: 127.0.0.1 + port: 5672 + username: guest + password: guest + application: + name: compute-service + #rabbitmq: + #host: localhost + #port: 5672 + #username: guest + #password: guest + redis: + ##Redis数据库索引(默认为0) + database: 0 + ##Redis服务器地址 + host: localhost + ##Redis服务器连接端口 + port: 6379 + ##Redis服务器连接密码(默认为空) + password: + ##连接超时时间(毫秒) + timeout: 0 + ##连接池相关参数设置 + pool: + ##连接池最大连接数(使用负值表示没有限制) + max-active: 8 + ##连接池最大阻塞等待时间(使用负值表示没有限制) + max-wait: -1 + ##连接池中的最大空闲连接 + max-idle: 8 + ##连接池中的最小空闲连接 + min-idle: 0 + ##zipkin: + ##base-url: http://localhost:9411 + ##sleuth: + ##sampler: + ##percentage: 1.0 +## cloud: +## config: +## uri: http://127.0.0.1:52099 +## name: sample-cloud-client +## profile: test + server: - port: 5558 \ No newline at end of file + port: 5558 + +eureka: + client: + serviceUrl: + ##defaultZone: http://william:123456@peer1:1314/eureka/ + defaultZone: http://localhost:1314/eureka/ + #healthcheck: + #enabled: true + +logging: + level: + root: INFO + org.springframework.web.servlet.DispatcherServlet: DEBUG \ No newline at end of file diff --git a/star-compute-service/src/main/resources/bootstrap.yml b/star-compute-service/src/main/resources/bootstrap.yml deleted file mode 100644 index ed4a7f7..0000000 --- a/star-compute-service/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,63 +0,0 @@ -## uri 这个值一定要和配置服务器保持一致 -## name 指定要从git远程仓库读取哪个文件 -## profile 指定读取文件的哪个版本(比如abc-test.yml 或者 abc-dev.yml文件) -## discovery 服务注册与发现 -#### 注意,最终读取的文件的名字是:name + "-" + profile + ".yml" 文件, 本例中就是读取sample-cloud-client-test.yml文件,这个优先级最高 -#### 如果此文件找不到,接着会去找application-test.yml文件,如果这个文件也没有,最后将会从客户端本地读取 -spring: - rabbitmq: - host: 127.0.0.1 - port: 5672 - username: guest - password: guest - application: - name: compute-service - #rabbitmq: - #host: localhost - #port: 5672 - #username: guest - #password: guest - redis: - ##Redis数据库索引(默认为0) - database: 0 - ##Redis服务器地址 - host: localhost - ##Redis服务器连接端口 - port: 6379 - ##Redis服务器连接密码(默认为空) - password: - ##连接超时时间(毫秒) - timeout: 0 - ##连接池相关参数设置 - pool: - ##连接池最大连接数(使用负值表示没有限制) - max-active: 8 - ##连接池最大阻塞等待时间(使用负值表示没有限制) - max-wait: -1 - ##连接池中的最大空闲连接 - max-idle: 8 - ##连接池中的最小空闲连接 - min-idle: 0 - ##zipkin: - ##base-url: http://localhost:9411 - ##sleuth: - ##sampler: - ##percentage: 1.0 -## cloud: -## config: -## uri: http://127.0.0.1:52099 -## name: sample-cloud-client -## profile: test - -eureka: - client: - serviceUrl: - ##defaultZone: http://william:123456@peer1:1314/eureka/ - defaultZone: http:/localhost:1314/eureka/ - healthcheck: - enabled: true - -logging: - level: - root: INFO - org.springframework.web.servlet.DispatcherServlet: DEBUG \ No newline at end of file diff --git a/star-compute-service/src/main/resources/logback-spring.xml b/star-compute-service/src/main/resources/logback-spring.xml index ebe5bd8..3a2659b 100644 --- a/star-compute-service/src/main/resources/logback-spring.xml +++ b/star-compute-service/src/main/resources/logback-spring.xml @@ -22,6 +22,7 @@ + + - + \ No newline at end of file From e98f8a542d476158fc20cc8a1cc95091fecc1d5f Mon Sep 17 00:00:00 2001 From: williamjava Date: Sat, 29 Dec 2018 08:55:25 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star-eureka-ribbon/pom.xml | 7 +++++++ .../java/com/gui/star_eureka_server/EurekaApplication.java | 3 --- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/star-eureka-ribbon/pom.xml b/star-eureka-ribbon/pom.xml index 6baa41e..41fa5d4 100644 --- a/star-eureka-ribbon/pom.xml +++ b/star-eureka-ribbon/pom.xml @@ -53,6 +53,13 @@ org.springframework.cloud spring-cloud-starter-netflix-hystrix + + + + org.springframework.boot + spring-boot-starter-actuator + true + diff --git a/star-eureka-server/src/main/java/com/gui/star_eureka_server/EurekaApplication.java b/star-eureka-server/src/main/java/com/gui/star_eureka_server/EurekaApplication.java index 8e91843..1705c72 100644 --- a/star-eureka-server/src/main/java/com/gui/star_eureka_server/EurekaApplication.java +++ b/star-eureka-server/src/main/java/com/gui/star_eureka_server/EurekaApplication.java @@ -22,8 +22,5 @@ public class EurekaApplication { public static void main(String[] args) { SpringApplication.run(EurekaApplication.class, args); - - // SpringApplication.run(EurekaApplication.class, - // "spring.profiles.active=peer1"); } } \ No newline at end of file From 90068e6354a746d7c948f007d9ee2a045e1fd566 Mon Sep 17 00:00:00 2001 From: williamjava Date: Sat, 29 Dec 2018 09:18:01 +0800 Subject: [PATCH 09/15] =?UTF-8?q?1.=E5=8D=87=E7=BA=A7SpringBoot=E7=89=88?= =?UTF-8?q?=E6=9C=AC=EF=BC=9B2.=E5=A2=9E=E5=8A=A0git=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star-configserver/.classpath | 2 +- star-configserver/.gitignore | 7 ++++++- .../.settings/org.eclipse.jdt.core.prefs | 6 +++--- star-configserver/pom.xml | 14 +++++++------- .../ConfigserverApplication.java | 3 ++- star-eureka-feign/.classpath | 2 +- star-eureka-feign/.gitignore | 7 ++++++- .../.settings/org.eclipse.jdt.core.prefs | 6 +++--- star-eureka-feign/pom.xml | 16 ++++++++-------- .../gui/star_eureka_feign/FeignApplication.java | 2 +- .../star_eureka_feign/face/ComputeClient.java | 2 +- .../ZipkinServerApplication.java | 6 ++++++ star-zuul/.classpath | 2 +- star-zuul/.gitignore | 7 ++++++- star-zuul/.settings/org.eclipse.jdt.core.prefs | 6 +++--- star-zuul/pom.xml | 9 ++++----- .../java/com/gui/star_zuul/ZuulApplication.java | 5 +++-- 17 files changed, 62 insertions(+), 40 deletions(-) diff --git a/star-configserver/.classpath b/star-configserver/.classpath index 6aff346..5d2afd4 100644 --- a/star-configserver/.classpath +++ b/star-configserver/.classpath @@ -18,7 +18,7 @@ - + diff --git a/star-configserver/.gitignore b/star-configserver/.gitignore index b83d222..6ebc895 100644 --- a/star-configserver/.gitignore +++ b/star-configserver/.gitignore @@ -1 +1,6 @@ -/target/ +.classpath +.project +.settings/ +.metadata/ +target/ +bin/ diff --git a/star-configserver/.settings/org.eclipse.jdt.core.prefs b/star-configserver/.settings/org.eclipse.jdt.core.prefs index 60105c1..714351a 100644 --- a/star-configserver/.settings/org.eclipse.jdt.core.prefs +++ b/star-configserver/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/star-configserver/pom.xml b/star-configserver/pom.xml index 5b3d23d..b16bf88 100644 --- a/star-configserver/pom.xml +++ b/star-configserver/pom.xml @@ -12,14 +12,14 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.5.RELEASE UTF-8 - williamjian - 0.4.13 + @@ -37,7 +37,7 @@ org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-netflix-eureka-client @@ -65,7 +65,7 @@ org.springframework.cloud spring-cloud-dependencies - Brixton.RELEASE + Finchley.RELEASE pom import @@ -85,7 +85,7 @@ - + diff --git a/star-configserver/src/main/java/com/gui/star_configserver/ConfigserverApplication.java b/star-configserver/src/main/java/com/gui/star_configserver/ConfigserverApplication.java index d4dc900..d6a0df1 100644 --- a/star-configserver/src/main/java/com/gui/star_configserver/ConfigserverApplication.java +++ b/star-configserver/src/main/java/com/gui/star_configserver/ConfigserverApplication.java @@ -1,5 +1,6 @@ package com.gui.star_configserver; +import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @@ -18,6 +19,6 @@ @SpringBootApplication public class ConfigserverApplication { public static void main(String[] args) { - new SpringApplicationBuilder(ConfigserverApplication.class).web(true).run(args); + new SpringApplicationBuilder(ConfigserverApplication.class).web(WebApplicationType.SERVLET).run(args); } } \ No newline at end of file diff --git a/star-eureka-feign/.classpath b/star-eureka-feign/.classpath index 6aff346..5d2afd4 100644 --- a/star-eureka-feign/.classpath +++ b/star-eureka-feign/.classpath @@ -18,7 +18,7 @@ - + diff --git a/star-eureka-feign/.gitignore b/star-eureka-feign/.gitignore index b83d222..6ebc895 100644 --- a/star-eureka-feign/.gitignore +++ b/star-eureka-feign/.gitignore @@ -1 +1,6 @@ -/target/ +.classpath +.project +.settings/ +.metadata/ +target/ +bin/ diff --git a/star-eureka-feign/.settings/org.eclipse.jdt.core.prefs b/star-eureka-feign/.settings/org.eclipse.jdt.core.prefs index 60105c1..714351a 100644 --- a/star-eureka-feign/.settings/org.eclipse.jdt.core.prefs +++ b/star-eureka-feign/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/star-eureka-feign/pom.xml b/star-eureka-feign/pom.xml index 9fcf953..11ed78a 100644 --- a/star-eureka-feign/pom.xml +++ b/star-eureka-feign/pom.xml @@ -11,26 +11,26 @@ UTF-8 - williamjian - 0.4.13 + org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.5.RELEASE org.springframework.cloud - spring-cloud-starter-feign + spring-cloud-starter-openfeign org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-netflix-eureka-client @@ -73,7 +73,7 @@ org.springframework.cloud spring-cloud-dependencies - Brixton.RELEASE + Finchley.RELEASE pom import @@ -93,7 +93,7 @@ - + diff --git a/star-eureka-feign/src/main/java/com/gui/star_eureka_feign/FeignApplication.java b/star-eureka-feign/src/main/java/com/gui/star_eureka_feign/FeignApplication.java index ea38c03..3ad94b4 100644 --- a/star-eureka-feign/src/main/java/com/gui/star_eureka_feign/FeignApplication.java +++ b/star-eureka-feign/src/main/java/com/gui/star_eureka_feign/FeignApplication.java @@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.cloud.openfeign.EnableFeignClients; /** * Feign是一个声明式的Web Service客户端,它使得编写Web Serivce客户端变得更加简单 diff --git a/star-eureka-feign/src/main/java/com/gui/star_eureka_feign/face/ComputeClient.java b/star-eureka-feign/src/main/java/com/gui/star_eureka_feign/face/ComputeClient.java index ee71b2d..42698d0 100644 --- a/star-eureka-feign/src/main/java/com/gui/star_eureka_feign/face/ComputeClient.java +++ b/star-eureka-feign/src/main/java/com/gui/star_eureka_feign/face/ComputeClient.java @@ -1,6 +1,6 @@ package com.gui.star_eureka_feign.face; -import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; diff --git a/star-zipkin-server/src/main/java/com/gui/star_zipkin_server/ZipkinServerApplication.java b/star-zipkin-server/src/main/java/com/gui/star_zipkin_server/ZipkinServerApplication.java index 601ae51..fb8583b 100644 --- a/star-zipkin-server/src/main/java/com/gui/star_zipkin_server/ZipkinServerApplication.java +++ b/star-zipkin-server/src/main/java/com/gui/star_zipkin_server/ZipkinServerApplication.java @@ -5,6 +5,12 @@ import zipkin.server.EnableZipkinServer; +/** + * SpringBoot2.0之后,zipkin-server不需要自己部署,该项目作废! + * + * @author wuhoujian + * + */ @EnableZipkinServer @SpringBootApplication public class ZipkinServerApplication { diff --git a/star-zuul/.classpath b/star-zuul/.classpath index edc9698..9b136af 100644 --- a/star-zuul/.classpath +++ b/star-zuul/.classpath @@ -17,7 +17,7 @@ - + diff --git a/star-zuul/.gitignore b/star-zuul/.gitignore index b83d222..6ebc895 100644 --- a/star-zuul/.gitignore +++ b/star-zuul/.gitignore @@ -1 +1,6 @@ -/target/ +.classpath +.project +.settings/ +.metadata/ +target/ +bin/ diff --git a/star-zuul/.settings/org.eclipse.jdt.core.prefs b/star-zuul/.settings/org.eclipse.jdt.core.prefs index 60105c1..714351a 100644 --- a/star-zuul/.settings/org.eclipse.jdt.core.prefs +++ b/star-zuul/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/star-zuul/pom.xml b/star-zuul/pom.xml index 9ae87cb..1b37a23 100644 --- a/star-zuul/pom.xml +++ b/star-zuul/pom.xml @@ -8,7 +8,6 @@ jar star-zuul - http://maven.apache.org UTF-8 @@ -17,7 +16,7 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.5.RELEASE @@ -25,12 +24,12 @@ org.springframework.cloud - spring-cloud-starter-zuul + spring-cloud-starter-netflix-zuul org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-netflix-eureka-client @@ -45,7 +44,7 @@ org.springframework.cloud spring-cloud-dependencies - Brixton.RELEASE + Finchley.RELEASE pom import diff --git a/star-zuul/src/main/java/com/gui/star_zuul/ZuulApplication.java b/star-zuul/src/main/java/com/gui/star_zuul/ZuulApplication.java index 4c393d7..368d1ba 100644 --- a/star-zuul/src/main/java/com/gui/star_zuul/ZuulApplication.java +++ b/star-zuul/src/main/java/com/gui/star_zuul/ZuulApplication.java @@ -1,5 +1,6 @@ package com.gui.star_zuul; +import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; @@ -19,9 +20,9 @@ @SpringCloudApplication public class ZuulApplication { public static void main(String[] args) { - new SpringApplicationBuilder(ZuulApplication.class).web(true).run(args); + new SpringApplicationBuilder(ZuulApplication.class).web(WebApplicationType.SERVLET).run(args); } - + @Bean public AccessFilter accessFilter() { return new AccessFilter(); From 772c5219c019bf0747730fdfb4a5f26046af787c Mon Sep 17 00:00:00 2001 From: wuhoujian Date: Mon, 15 Apr 2019 16:05:11 +0800 Subject: [PATCH 10/15] test --- star-eureka-server/.idea/workspace.xml | 396 +++++++++++++++++++++++++ 1 file changed, 396 insertions(+) create mode 100644 star-eureka-server/.idea/workspace.xml diff --git a/star-eureka-server/.idea/workspace.xml b/star-eureka-server/.idea/workspace.xml new file mode 100644 index 0000000..79a8460 --- /dev/null +++ b/star-eureka-server/.idea/workspace.xml @@ -0,0 +1,396 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -56,9 +148,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -212,14 +204,19 @@ - - + + - + + + + + + - + + + + + + + + + + + + @@ -288,15 +306,32 @@ + + + + + 1555322290754 + + + 1555379922630 + + - - @@ -304,7 +339,7 @@ - + @@ -317,8 +352,8 @@ - - + + @@ -337,10 +372,11 @@ + + + - - - @@ -390,189 +426,247 @@ - + - - + + - - + - - + + - - + + + + + + - + - - + + - + - - + + - + - - + + - + - - + + + + + + - + + + + + + + + + + + - - + + - + + + + - - + + - + - - + + - + - - - - - - + + - + - - + + - + - - + + - + - - + + - + - - - - - - + + - + - - + + - + - - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - + - - + + - + - - + + - + - - + + - + - - + + - - + + + + + + - + - - + + - + - - + + - + - - + + @@ -628,7 +722,7 @@ - star-eureka-ribbon + star-configserver