重构bean name
@Component("beanNameGenerator")
public class BeanNameGenerator extends AnnotationBeanNameGenerator {
@Override
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
//如果有设置了value,则用value,否则使用全类名
// if(definition instanceof AnnotatedBeanDefinition){
// String beanName=determineBeanNameFromAnnotation((AnnotatedBeanDefinition) definition);
// if(StringUtils.hasText(beanName)){
// return beanName;
// }else{
// beanName=definition.getBeanClassName();
// return beanName;
// }
// }
// //默认全类名
return buildDefaultBeanName(definition, registry);
// return definition.getBeanClassName();
// return definition.getBeanClassName();
// return definition.getBeanClassName();
String beanClassName = definition.getBeanClassName();
if(beanClassName.contains("SysSequenceMapper")){
// System.out.println(beanClassName);
}
Assert.state(beanClassName != null, "No bean class name set");
//分割类全路径
String[] packages = beanClassName.split("\\.");
StringBuilder beanName = new StringBuilder();
//取类的包名的首字母小写再加上类名作为最后的bean名
for (int i = 0; i < packages.length - 1; i++) {
beanName.append(packages[i].toLowerCase().charAt(0));
}
beanName.append(packages[packages.length - 1]);
System.out.println(beanName.toString());
return beanName.toString();
}
}