When you use @Inject
, CDI tries to create an instance of the requested type for you. The simplest solution: It calls the default constructor and returns that instance.
Problem with java.util.logging.Logger
: it has no visible default constructor. So you have to tell CDI how to satisfy the dependency by adding a Producer to your classpath. Although using the weld-logger @JohnAment suggested would be my prefered solution as well, given your current state of knowledge its probably best for you, if you start by adding your own producer.
So beside your controller, create a new Class (add package, import, ... yourself)
public class LoggerProducer {
@Produces
public Logger getLogger(InjectionPoint p) {
return Logger.getLogger(p.getClass().getCanonicalName());
}
}
This tells the CDI container: whenever you need to inject a java.util.logging.Logger
, use this method to create one by taking the fqn name of the class where that logger reference is needed.
This should solve your problem. Once you got the idea, think if you really want/need to use java.util.logging or if you want to switch to slf4j. In that case, modify your controller imports, remove the LoggerProducer you just wrote and import the weld-logger jar to your deployment instead.