weld cdi add bean programticlly

774 views Asked by At

i'm trying to manually load an javax annotated class and register it as a bean in a java ee 7 (wildfly) container (using weld) , i have written an extentions using deltaspike BeanBuilder:

  public void afterBeanDiscovery(@Observes AfterBeanDiscovery after, BeanManager beanMgr) {
    // read the annotations of our class
    AnnotatedType annotatedType=beanMgr.createAnnotatedType(Logger.class);
    after.addBean(new BeanBuilder(beanMgr).readFromType(annotatedType).passivationCapable(true).create());
    annotatedType=beanMgr.createAnnotatedType(XMLRepository.class);
    after.addBean(new BeanBuilder<>(beanMgr).readFromType(annotatedType).passivationCapable(true).create());
    for (Class<?> aClass : clazz) {
       AnnotatedType at= beanMgr.createAnnotatedType(aClass);

       Bean bean = new BeanBuilder(beanMgr).readFromType(at).passivationCapable(true).create();
        after.addBean(bean);
    }



}

AnnotatedType<T> plugType = bm.createAnnotatedType(pluginClass);
    BeanAttributes<T> beanAttr = bm.createBeanAttributes(plugType);
    InjectionTargetFactory<T> factory = bm.getInjectionTargetFactory(plugType);
    Bean<T> bean = beanmanagerweld.createBean(beanAttr, pluginClass, factory);

where clazz is a set of plugin classes , i'm getting missing injected dependencies of Logger which is a container managed class ,any idea how to solve these issues ? Thanks.

EDIT:

here is the bean i am trying to load via the extension

  package processing;

    import javax.inject.Inject;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import java.util.regex.Matcher;

/**
 * Created by Asaf on 29/09/2016.
 */


    @PluginInfo(version = 1)
    public class Binder implements ServicePlugin {

        @Inject
        private Logger logger;


        private void log(String s) {
            logger.info(s);
        }

    }

note that @plugininfo and Service plugin are just markers for me so i know this class should be loaded they do not contain any codes or methods to implement

the exact error is:

WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [@Default] at injection point [[field] @Inject private processing.Binder.logger]

0

There are 0 answers