diff --git a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/AutoConfiguredRetrofitScannerRegistrar.java b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/AutoConfiguredRetrofitScannerRegistrar.java index 00902d4..2fb72d0 100644 --- a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/AutoConfiguredRetrofitScannerRegistrar.java +++ b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/AutoConfiguredRetrofitScannerRegistrar.java @@ -9,10 +9,8 @@ import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.boot.autoconfigure.AutoConfigurationPackages; -import org.springframework.context.EnvironmentAware; import org.springframework.context.ResourceLoaderAware; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; -import org.springframework.core.env.Environment; import org.springframework.core.io.ResourceLoader; import org.springframework.core.type.AnnotationMetadata; @@ -25,7 +23,7 @@ * * @author 陈添明 */ -public class AutoConfiguredRetrofitScannerRegistrar implements BeanFactoryAware, ImportBeanDefinitionRegistrar, ResourceLoaderAware, BeanClassLoaderAware, EnvironmentAware { +public class AutoConfiguredRetrofitScannerRegistrar implements BeanFactoryAware, ImportBeanDefinitionRegistrar, ResourceLoaderAware, BeanClassLoaderAware { private static final Logger logger = LoggerFactory.getLogger(AutoConfiguredRetrofitScannerRegistrar.class); @@ -34,7 +32,6 @@ public class AutoConfiguredRetrofitScannerRegistrar implements BeanFactoryAware, private ResourceLoader resourceLoader; private ClassLoader classLoader; - private Environment environment; @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { @@ -57,7 +54,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B } // Scan the @RetrofitClient annotated interface under the specified path and register it to the BeanDefinitionRegistry - ClassPathRetrofitClientScanner scanner = new ClassPathRetrofitClientScanner(registry, classLoader, environment); + ClassPathRetrofitClientScanner scanner = new ClassPathRetrofitClientScanner(registry, classLoader); if (resourceLoader != null) { scanner.setResourceLoader(resourceLoader); } @@ -78,9 +75,4 @@ public void setResourceLoader(ResourceLoader resourceLoader) { public void setBeanClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } - - @Override - public void setEnvironment(Environment environment) { - this.environment = environment; - } } 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 f65cf7f..7e4300c 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 @@ -8,10 +8,8 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; -import org.springframework.core.env.Environment; import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.util.ClassUtils; -import org.springframework.util.StringUtils; import java.util.Arrays; import java.util.Objects; @@ -25,12 +23,10 @@ public class ClassPathRetrofitClientScanner extends ClassPathBeanDefinitionScann private final ClassLoader classLoader; private final static Logger logger = LoggerFactory.getLogger(ClassPathRetrofitClientScanner.class); - private final Environment environment; - public ClassPathRetrofitClientScanner(BeanDefinitionRegistry registry, ClassLoader classLoader, Environment environment) { + public ClassPathRetrofitClientScanner(BeanDefinitionRegistry registry, ClassLoader classLoader) { super(registry, false); this.classLoader = classLoader; - this.environment = environment; } public void registerFilters() { @@ -58,8 +54,7 @@ protected boolean isCandidateComponent( Class target = ClassUtils.forName( beanDefinition.getMetadata().getClassName(), classLoader); - - return !target.isAnnotation() && (legalBaseUrl(target) || legalServiceId(target)); + return !target.isAnnotation(); } catch (Exception ex) { logger.error("load class exception:", ex); } @@ -67,40 +62,6 @@ protected boolean isCandidateComponent( return false; } - private boolean legalBaseUrl(Class target) { - final RetrofitClient retrofitClient = target.getAnnotation(RetrofitClient.class); - final String baseUrl = retrofitClient.baseUrl(); - if (StringUtils.isEmpty(baseUrl)) { - logger.warn("No config baseUrl! interface={}", target); - return false; - } - - try { - environment.resolveRequiredPlaceholders(baseUrl); - } catch (Exception e) { - logger.warn("No config baseUrl! interface={}", target); - return false; - } - 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; diff --git a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitClientScannerRegistrar.java b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitClientScannerRegistrar.java index 4ac3d41..bc846ed 100644 --- a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitClientScannerRegistrar.java +++ b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitClientScannerRegistrar.java @@ -3,11 +3,9 @@ import com.github.lianjiatech.retrofit.spring.boot.annotation.RetrofitScan; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.context.EnvironmentAware; import org.springframework.context.ResourceLoaderAware; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.annotation.AnnotationAttributes; -import org.springframework.core.env.Environment; import org.springframework.core.io.ResourceLoader; import org.springframework.core.type.AnnotationMetadata; import org.springframework.util.Assert; @@ -21,14 +19,12 @@ /** * @author 陈添明 */ -public class RetrofitClientScannerRegistrar implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, BeanClassLoaderAware, EnvironmentAware { +public class RetrofitClientScannerRegistrar implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, BeanClassLoaderAware { private ResourceLoader resourceLoader; private ClassLoader classLoader; - private Environment environment; - @Override public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { AnnotationAttributes attributes = AnnotationAttributes @@ -37,7 +33,7 @@ public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionR return; } // Scan the @RetrofitClient annotated interface under the specified path and register it to the BeanDefinitionRegistry - ClassPathRetrofitClientScanner scanner = new ClassPathRetrofitClientScanner(registry, classLoader, environment); + ClassPathRetrofitClientScanner scanner = new ClassPathRetrofitClientScanner(registry, classLoader); if (resourceLoader != null) { scanner.setResourceLoader(resourceLoader); } @@ -82,9 +78,4 @@ public void setResourceLoader(ResourceLoader resourceLoader) { public void setBeanClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } - - @Override - public void setEnvironment(Environment environment) { - this.environment = environment; - } }