From d43a90ae98d2a0eced3c5a349b0d5a7c2e2a56ed Mon Sep 17 00:00:00 2001 From: chentianming Date: Fri, 6 Aug 2021 11:47:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E9=85=8D=E7=BD=AEbaseUrl=E5=B9=B6?= =?UTF-8?q?=E4=B8=94=E6=9C=AA=E9=85=8D=E7=BD=AEserviceId=E5=BF=BD=E8=A7=86?= =?UTF-8?q?=E8=AF=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- README_EN.md | 4 ++-- pom.xml | 2 +- .../core/ClassPathRetrofitClientScanner.java | 19 ++++++++++++++++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d9c5504..9d33fd1 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ gitee项目地址:[https://gitee.com/lianjiatech/retrofit-spring-boot-starter] com.github.lianjiatech retrofit-spring-boot-starter - 2.2.13 + 2.2.14 ``` @@ -63,7 +63,7 @@ gitee项目地址:[https://gitee.com/lianjiatech/retrofit-spring-boot-starter] com.github.lianjiatech retrofit-spring-boot-starter - 2.2.13 + 2.2.14 com.squareup.okhttp3 diff --git a/README_EN.md b/README_EN.md index bb183ae..6093711 100644 --- a/README_EN.md +++ b/README_EN.md @@ -43,7 +43,7 @@ com.github.lianjiatech retrofit-spring-boot-starter - 2.2.13 + 2.2.14 ``` @@ -53,7 +53,7 @@ This project depends on Retrofit-2.9.0, okhttp-3.14.9, and okio-1.17.5 versions. com.github.lianjiatech retrofit-spring-boot-starter - 2.2.13 + 2.2.14 com.squareup.okhttp3 diff --git a/pom.xml b/pom.xml index 90da40a..96212ec 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.lianjiatech retrofit-spring-boot-starter - 2.2.13 + 2.2.14 retrofit-spring-boot-starter retrofit-spring-boot-starter diff --git a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/ClassPathRetrofitClientScanner.java b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/ClassPathRetrofitClientScanner.java index 487cae2..f65cf7f 100644 --- a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/ClassPathRetrofitClientScanner.java +++ b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/ClassPathRetrofitClientScanner.java @@ -59,7 +59,7 @@ protected boolean isCandidateComponent( beanDefinition.getMetadata().getClassName(), classLoader); - return !target.isAnnotation() && legalBaseUrl(target); + return !target.isAnnotation() && (legalBaseUrl(target) || legalServiceId(target)); } catch (Exception ex) { logger.error("load class exception:", ex); } @@ -84,6 +84,23 @@ private boolean legalBaseUrl(Class target) { return true; } + private boolean legalServiceId(Class target) { + final RetrofitClient retrofitClient = target.getAnnotation(RetrofitClient.class); + final String serviceId = retrofitClient.serviceId(); + if (StringUtils.isEmpty(serviceId)) { + logger.warn("No config serviceId! interface={}", target); + return false; + } + + try { + environment.resolveRequiredPlaceholders(serviceId); + } catch (Exception e) { + logger.warn("No config serviceId! interface={}", target); + return false; + } + return true; + } + private void processBeanDefinitions(Set beanDefinitions) { GenericBeanDefinition definition;