feat:清理代码,新版spring支持自动注入,无需手动注入

This commit is contained in:
wangyu 2021-12-08 16:46:40 +08:00
parent 117ca1e3c4
commit bc9333db81

View File

@ -104,12 +104,11 @@ public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, Res
.setUri(makePath(clazz.getSimpleName(), restBean.value()));
// 分别生成实现类从repo到controller
templates.forEach((type, template) -> {
Class<?> superClass = superClasses.getOrDefault(type, noOp).apply(restBean);
// 当且仅当存在vo时才编译view-controller
if (testNotSupport(superClass, type, hasVo)) {
if (testNotSupport(restBean, type, hasVo)) {
return;
}
source.setSuperClass(superClass.getCanonicalName());
source.setSuperClass(superClasses.getOrDefault(type, noOp).apply(restBean).getCanonicalName());
source.setClassName(clazz.getSimpleName() + type.getName());
try {
log.info("尝试注册{}", source.getClassName());
@ -196,17 +195,18 @@ public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, Res
/**
* 测试是否支持vo
*
* @param clazz 父类
* @param bean 定义
* @param type 注入类型
* @param hasVo 是否有vo
* @return 结果
*/
private boolean testNotSupport(Class<?> clazz, RestBeanCandidate type, boolean hasVo) {
private boolean testNotSupport(RestBean bean, RestBeanCandidate type, boolean hasVo) {
Class<?> superClass = superClasses.get(REPOSITORY).apply(bean);
switch (type) {
case VIEW_CONTROLLER:
return !hasVo || !DefaultRepository.class.isAssignableFrom(clazz);
return !hasVo || !DefaultRepository.class.isAssignableFrom(superClass);
case REACTIVE_VIEW_CONTROLLER:
return !hasVo || !DefaultReactiveRepository.class.isAssignableFrom(clazz);
return !hasVo || !DefaultReactiveRepository.class.isAssignableFrom(superClass);
default:
return false;
}