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

cn.willingxyz.restdoc.spring.SpringControllerResolver Maven / Gradle / Ivy

There is a newer version: 0.2.1.4
Show newest version
package cn.willingxyz.restdoc.spring;

import cn.willingxyz.restdoc.core.parse.IControllerResolver;
import lombok.var;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.List;

public class SpringControllerResolver implements IControllerResolver {
    private static Logger _logger = LoggerFactory.getLogger(SpringControllerResolver.class);

    private List _packages;

    public SpringControllerResolver(List packages)
    {
        _packages = packages;
    }

    @Override
    public List getClasses() {
        var scanner = new ClassPathScanningCandidateComponentProvider(false);
        scanner.addIncludeFilter(new AnnotationTypeFilter(Controller.class));

        var classes = new ArrayList();
        for (var packageName : _packages) {
            var beans = scanner.findCandidateComponents(packageName);
            for (var bean : beans) {
                try {
                    var className = bean.getBeanClassName();
                    Class clazz = Class.forName(className);
                    classes.add(clazz);
                } catch (ClassNotFoundException e) {
                    _logger.warn("not found class:" + bean.getBeanClassName(), e);
                }
            }
        }
        return classes;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy