我正在使用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的原因。