Skip to content

Commit

Permalink
回到2.2.12版本,发布2.2.15
Browse files Browse the repository at this point in the history
移除前置配置检测功能
  • Loading branch information
chentianming11 committed Aug 27, 2021
1 parent 165af17 commit 0108e20
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand All @@ -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 {
Expand All @@ -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);
}
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -58,49 +54,14 @@ 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);
}
}
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<BeanDefinitionHolder> beanDefinitions) {
GenericBeanDefinition definition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 0108e20

Please sign in to comment.