com.astamuse.asta4d.misc.spring.Asta4dBeanNameGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of asta4d-spring Show documentation
Show all versions of asta4d-spring Show documentation
interaction with springframework
The newest version!
package com.astamuse.asta4d.misc.spring;
import java.util.Arrays;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
public class Asta4dBeanNameGenerator extends AnnotationBeanNameGenerator {
private String[] snippetSearchPathList;
@Override
protected String buildDefaultBeanName(BeanDefinition definition) {
if (snippetSearchPathList == null) {
return super.buildDefaultBeanName(definition);
}
String clsName = definition.getBeanClassName();
for (String s : snippetSearchPathList) {
if (clsName.startsWith(s)) {
return clsName.substring(s.length());
}
}
return super.buildDefaultBeanName(definition);
}
public void setSnippetSearchPathList(String... snippetSearchPathList) {
this.snippetSearchPathList = Arrays.stream(snippetSearchPathList).map(s -> s + ".").toArray(len -> new String[len]);
}
}