mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-10 21:19:00 +08:00
🎨 改进结构和代码格式. add spring-javaformat plugin and format all code
This commit is contained in:
1 parent
5414983f3d
commit
bd47066299
651 files changed
+13034
-12462
No files matched your search
+5
-6
@@ -33,11 +33,11 @@ import java.lang.annotation.*;
|
||||
@EnableFeignClients
|
||||
@Import(PigxFeignClientsRegistrar.class)
|
||||
public @interface EnablePigxFeignClients {
|
||||
|
||||
/**
|
||||
* Alias for the {@link #basePackages()} attribute. Allows for more concise annotation
|
||||
* declarations e.g.: {@code @ComponentScan("org.my.pkg")} instead of
|
||||
* {@code @ComponentScan(basePackages="org.my.pkg")}.
|
||||
*
|
||||
* @return the array of 'basePackages'.
|
||||
*/
|
||||
String[] value() default {};
|
||||
@@ -49,10 +49,9 @@ public @interface EnablePigxFeignClients {
|
||||
* <p>
|
||||
* Use {@link #basePackageClasses()} for a type-safe alternative to String-based
|
||||
* package names.
|
||||
*
|
||||
* @return the array of 'basePackages'.
|
||||
*/
|
||||
String[] basePackages() default {"com.pig4cloud.pigx"};
|
||||
String[] basePackages() default { "com.pig4cloud.pigx" };
|
||||
|
||||
/**
|
||||
* Type-safe alternative to {@link #basePackages()} for specifying the packages to
|
||||
@@ -60,7 +59,6 @@ public @interface EnablePigxFeignClients {
|
||||
* <p>
|
||||
* Consider creating a special no-op marker class or interface in each package that
|
||||
* serves no purpose other than being referenced by this attribute.
|
||||
*
|
||||
* @return the array of 'basePackageClasses'.
|
||||
*/
|
||||
Class<?>[] basePackageClasses() default {};
|
||||
@@ -75,9 +73,10 @@ public @interface EnablePigxFeignClients {
|
||||
Class<?>[] defaultConfiguration() default {};
|
||||
|
||||
/**
|
||||
* List of classes annotated with @FeignClient. If not empty, disables classpath scanning.
|
||||
*
|
||||
* List of classes annotated with @FeignClient. If not empty, disables classpath
|
||||
* scanning.
|
||||
* @return
|
||||
*/
|
||||
Class<?>[] clients() default {};
|
||||
|
||||
}
|
||||
+14
-1
@@ -26,7 +26,9 @@ import java.util.Set;
|
||||
*/
|
||||
@Endpoint(id = "feign")
|
||||
public class FeignClientEndpoint implements SmartInitializingSingleton {
|
||||
|
||||
private final ApplicationContext context;
|
||||
|
||||
private final List<FeignClientInfo> clientList;
|
||||
|
||||
public FeignClientEndpoint(ApplicationContext context) {
|
||||
@@ -80,7 +82,8 @@ public class FeignClientEndpoint implements SmartInitializingSingleton {
|
||||
if (method.isDefault()) {
|
||||
continue;
|
||||
}
|
||||
RequestMapping requestMapping = AnnotatedElementUtils.getMergedAnnotation(method, RequestMapping.class);
|
||||
RequestMapping requestMapping = AnnotatedElementUtils.getMergedAnnotation(method,
|
||||
RequestMapping.class);
|
||||
if (requestMapping == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -96,19 +99,29 @@ public class FeignClientEndpoint implements SmartInitializingSingleton {
|
||||
@Getter
|
||||
@Setter
|
||||
public static class FeignClientInfo {
|
||||
|
||||
private String beanName;
|
||||
|
||||
private String serviceId;
|
||||
|
||||
private String contextId;
|
||||
|
||||
private String url;
|
||||
|
||||
private String path;
|
||||
|
||||
private List<ClientInfo> clientList;
|
||||
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public static class ClientInfo {
|
||||
|
||||
private final RequestMethod[] methods;
|
||||
|
||||
private final String[] mappings;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+20
-10
@@ -44,9 +44,12 @@ import java.util.Map;
|
||||
* <p>
|
||||
* feign 自动配置功能 from mica
|
||||
*/
|
||||
public class PigxFeignClientsRegistrar implements ImportBeanDefinitionRegistrar, BeanClassLoaderAware, EnvironmentAware {
|
||||
public class PigxFeignClientsRegistrar
|
||||
implements ImportBeanDefinitionRegistrar, BeanClassLoaderAware, EnvironmentAware {
|
||||
|
||||
@Getter
|
||||
private ClassLoader beanClassLoader;
|
||||
|
||||
@Getter
|
||||
private Environment environment;
|
||||
|
||||
@@ -61,7 +64,8 @@ public class PigxFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
|
||||
}
|
||||
|
||||
private void registerFeignClients(BeanDefinitionRegistry registry) {
|
||||
List<String> feignClients = SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(), getBeanClassLoader());
|
||||
List<String> feignClients = SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(),
|
||||
getBeanClassLoader());
|
||||
// 如果 spring.factories 里为空
|
||||
if (feignClients.isEmpty()) {
|
||||
return;
|
||||
@@ -69,7 +73,8 @@ public class PigxFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
|
||||
for (String className : feignClients) {
|
||||
try {
|
||||
Class<?> clazz = beanClassLoader.loadClass(className);
|
||||
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, FeignClient.class);
|
||||
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz,
|
||||
FeignClient.class);
|
||||
if (attributes == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -80,7 +85,8 @@ public class PigxFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
|
||||
registerClientConfiguration(registry, getClientName(attributes), attributes.get("configuration"));
|
||||
|
||||
validate(attributes);
|
||||
BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(FeignClientFactoryBean.class);
|
||||
BeanDefinitionBuilder definition = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(FeignClientFactoryBean.class);
|
||||
definition.addPropertyValue("url", getUrl(attributes));
|
||||
definition.addPropertyValue("path", getPath(attributes));
|
||||
String name = getName(attributes);
|
||||
@@ -92,7 +98,8 @@ public class PigxFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
|
||||
String contextId = getContextId(attributes);
|
||||
aliasBuilder.append(contextId);
|
||||
definition.addPropertyValue("contextId", contextId);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
aliasBuilder.append(name);
|
||||
}
|
||||
|
||||
@@ -117,10 +124,12 @@ public class PigxFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
|
||||
alias = qualifier;
|
||||
}
|
||||
|
||||
BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className, new String[]{alias});
|
||||
BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className,
|
||||
new String[] { alias });
|
||||
BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -129,7 +138,6 @@ public class PigxFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
|
||||
/**
|
||||
* Return the class used by {@link SpringFactoriesLoader} to load configuration
|
||||
* candidates.
|
||||
*
|
||||
* @return the factory class
|
||||
*/
|
||||
private Class<?> getSpringFactoriesLoaderFactoryClass() {
|
||||
@@ -213,14 +221,16 @@ public class PigxFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
|
||||
return value;
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Either 'name' or 'value' must be provided in @" + FeignClient.class.getSimpleName());
|
||||
throw new IllegalStateException(
|
||||
"Either 'name' or 'value' must be provided in @" + FeignClient.class.getSimpleName());
|
||||
}
|
||||
|
||||
private void registerClientConfiguration(BeanDefinitionRegistry registry, Object name, Object configuration) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FeignClientSpecification.class);
|
||||
builder.addConstructorArgValue(name);
|
||||
builder.addConstructorArgValue(configuration);
|
||||
registry.registerBeanDefinition(name + "." + FeignClientSpecification.class.getSimpleName(), builder.getBeanDefinition());
|
||||
registry.registerBeanDefinition(name + "." + FeignClientSpecification.class.getSimpleName(),
|
||||
builder.getBeanDefinition());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user