0

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]

asafb
  • 92
  • 7
  • Please include a stacktrace as well as some code samples of what your bean looks like. The current sample is hard to follow since you have a block of code without any context. – John Ament Dec 23 '16 at 15:39
  • Hi John, thanks for the reply i have added the bean code and the exact error received – asafb Dec 25 '16 at 08:40
  • Ok, thanks. Did you provide producer for `java.util.logging.Logger`? There is none built in. – John Ament Dec 25 '16 at 13:32
  • there is one provided by JavaEE specs (wildfly) – asafb Dec 26 '16 at 14:17
  • there is one provided by JavaEE specs (wildfly), note that if a place the Binder class with the javaEE application (with the extension) everything works as it should , but loading it using the extension failes – asafb Dec 26 '16 at 14:18
  • Could you share a link to some docs saying that logger is provided? It's not as far as I know. – John Ament Dec 26 '16 at 14:49
  • You are right , there is no mention of it in the specs , but it is provided in my environment- not explicitly though , I'll soon take a look who produces the logger bean I have there , my guess is that it's probably wildfly itself ,but I'll make sure . there is no problem with injecting it if I don't programticly load it via the extension – asafb Dec 26 '16 at 16:12
  • Wildfly does not provide it, and Weld does not provide. This is why you're not able to use it. – John Ament Dec 26 '16 at 16:14
  • couldnt find any info about it , but all the regular classes are being injected with logger without any problem and i dont have any logger producer in my code, the logger type is of org.jboss.logmanager.Logger – asafb Dec 29 '16 at 14:12

0 Answers0