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

dev.alangomes.springspigot.picocli.SpringCommandFactory Maven / Gradle / Ivy

There is a newer version: 0.20.7
Show newest version
package dev.alangomes.springspigot.picocli;

import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import picocli.CommandLine;

@Component
class SpringCommandFactory implements CommandLine.IFactory {

    @Autowired
    private BeanFactory beanFactory;

    @Override
    public  K create(Class cls) throws Exception {
        K bean = beanFactory.getBean(cls);
        if (!(bean instanceof Iterable) && AopUtils.isAopProxy(bean)) {
            return (K) ((Advised) bean).getTargetSource().getTarget();
        }
        return bean;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy