Rémi Doolaeghe Rémi Doolaeghe - 5 months ago 47
Java Question

Seam Weld injection in constructor : Unable to resolve any beans for Types

I'm using Weld 1.0. Here's my situation: I have a class instantiating a Weld container which tries to instantiate a class

StartupShutdown
:

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

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


Here's my class
StartupShutdown
:

public class StartupShutdown {

@Inject
public StartupShutdown(LoggingFileHandler loggingFileHandler) {
}
}


I got this exception:

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)


When I remove the parameter in the
StartupShutdown
constructor, it works.

Just for info, here's my
LoggingFileHandler
:

public class LoggingFileHandler extends FileHandler {

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


What's wrong with this parameter in my constructor?

Answer

Shame on me! I just put LoggingFileHandler accidentally in my src/test/java. Works fine now. That's why the Bean could not be found.