我正在使用Weld 1.0。这是我的情况:我有一个实例化Weld容器的类,该容器尝试实例化StartupShutdown类:

public static void main(String[] args) {
    WeldContainer weld;
    weld = new Weld().initialize();

    StartupShutdown startupShutdown = weld.instance().select(StartupShutdown.class).get();
}


这是我的课程StartupShutdown

public class StartupShutdown {

    @Inject
    public StartupShutdown(LoggingFileHandler loggingFileHandler) {
    }
}


我有这个例外:

Exception in thread "main" org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308 Unable to resolve any beans for Types: [class fr.easycompany.easywrite.processes.StartupShutdown]; Bindings: [QualifierInstance{annotationClass=interface javax.enterprise.inject.Default, values={}, hashCode=2062316647}]
    at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:728)
    at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:102)
    at fr.easycompany.easywrite.EasyWrite.main(EasyWrite.java:18)


当我在StartupShutdown构造函数中删除参数时,它可以工作。

仅供参考,这是我的LoggingFileHandler

public class LoggingFileHandler extends FileHandler {

    @Inject
    public LoggingFileHandler(LoggingFormatter formatter) throws IOException, SecurityException {
        super("");
        this.setFormatter(formatter);
    }
}


我的构造函数中的此参数有什么问题?

最佳答案

真可惜!我只是将LoggingFileHandler意外地放入了src/test/java中。现在工作正常。这就是为什么找不到Bean的原因。

10-04 19:10