diff options
author | gjoranv <gv@verizonmedia.com> | 2021-10-15 17:38:04 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2021-10-15 18:26:50 +0200 |
commit | 5bad2e56ea6aa39cc8fe062828eb4471eacda7d9 (patch) | |
tree | 45d1c32a18ec2496aee8e32635d2323e0310d947 /container-core/src/main/java/com/yahoo | |
parent | e138d9f977423cda5a200eab82383d73c20ee05e (diff) |
Warn if the fallback injector is used for unknown classes,
.. and log a debug message when our explicit bindings are used.
Diffstat (limited to 'container-core/src/main/java/com/yahoo')
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java b/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java index 049aad84cfe..c6c932d8743 100644 --- a/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java +++ b/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java @@ -258,10 +258,12 @@ public class ComponentGraph { if (component.isEmpty()) { Object instance; try { - // This is an indication that you have not set up your components correctly in the model - // And tit will cause unnecessary reconstruction of your components. - // TODO: this should perhaps bee a warning. - log.log(Level.INFO, () -> "Trying the fallback injector to create" + messageForNoGlobalComponent(clazz, node)); + Level level = hasExplicitBinding(fallbackInjector, key) ? Level.FINE : Level.WARNING; + log.log(level, () ->"Trying the fallback injector to create" + messageForNoGlobalComponent(clazz, node)); + if (level.intValue() > Level.INFO.intValue()) { + log.log(level, "A component of type " + key.getTypeLiteral() + " should probably be declared in services.xml. " + + "Not doing so may cause resource leaks and unnecessary reconstruction of components."); + } instance = fallbackInjector.getInstance(key); } catch (ConfigurationException e) { throw removeStackTrace(new IllegalStateException( @@ -277,6 +279,11 @@ public class ComponentGraph { return component.get(); } + private boolean hasExplicitBinding(Injector injector, Key<?> key) { + log.log(Level.FINE, () -> "Injector binding for " + key + ": " + injector.getExistingBinding(key)); + return injector.getExistingBinding(key) != null; + } + private Node handleComponentParameter(Node node, Injector fallbackInjector, Class<?> clazz, Collection<Annotation> annotations) { List<Annotation> bindingAnnotations = annotations.stream().filter(ComponentGraph::isBindingAnnotation).collect(Collectors.toList()); |