dev.alangomes.springspigot.ScopePostProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spigot-spring-boot-starter Show documentation
Show all versions of spigot-spring-boot-starter Show documentation
Spring support for spigot plugins
package dev.alangomes.springspigot;
import dev.alangomes.springspigot.scope.SenderContextScope;
import lombok.val;
import org.bukkit.event.Listener;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import java.util.Arrays;
import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_SINGLETON;
class ScopePostProcessor implements BeanFactoryPostProcessor {
private SenderContextScope senderContextScope;
ScopePostProcessor(SenderContextScope senderContextScope) {
this.senderContextScope = senderContextScope;
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {
factory.registerScope("sender", senderContextScope);
Arrays.stream(factory.getBeanDefinitionNames()).forEach(beanName -> {
val beanDef = factory.getBeanDefinition(beanName);
val beanType = factory.getType(beanName);
if (beanType != null && beanType.isAssignableFrom(Listener.class)) {
beanDef.setScope(SCOPE_SINGLETON);
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy