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

com.daiyc.extension.boot.ExtensionContextBean Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package com.daiyc.extension.boot;

import com.daiyc.extension.core.ExtensionContext;
import com.daiyc.extension.core.annotations.Extension;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author daiyc
 * @since 2024/8/6
 */
@Component
public class ExtensionContextBean extends ExtensionContext implements ApplicationContextAware, SmartInitializingSingleton {
    private ApplicationContext applicationContext;

    @Override
    public void afterSingletonsInstantiated() {
        Map beanMap = applicationContext.getBeansWithAnnotation(Extension.class);

        for (Object bean : beanMap.values()) {
            this.register((Class) bean.getClass(), bean);
        }
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy