All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.astamuse.asta4d.misc.spring.Asta4dBeanNameGenerator Maven / Gradle / Ivy

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]);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy