Quick revision
The short answer
If the handler's constructor runs but the bean is not in List<EventHandler>, Spring created it but did not consider it a matching candidate for that injection point. The usual causes are that the bean's final type is not an EventHandler, for example a proxy created only for other interfaces; that its generic type does not match, such as EventHandler<PaymentEvent> when the list asks for EventHandler<OrderEvent>; that it lives in a child or different context from the injecting bean; or that it is marked autowireCandidate = false or defaultCandidate = false (check your version for the latter).
What to remember
In this answer, we saw that a constructor message only proves an instance was created, not that the bean matches List<EventHandler>. The bean may have been replaced by a proxy that does not implement EventHandler, its generic type may not match the list's, it may live in a child or different context that the injecting bean cannot see, or it may be excluded with autowireCandidate = false or defaultCandidate = false. A few container queries, getBeansOfType, the bean's class, a wildcard generic and isAutowireCandidate, tell us which in minutes.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
If the handler's constructor runs but the bean is not in List<EventHandler>, Spring created it but did not consider it a matching candidate for that injection point. The usual causes are that the bean's final type is not an EventHandler, for example a proxy created only for other interfaces; that its generic type does not match, such as EventHandler<PaymentEvent> when the list asks for EventHandler<OrderEvent>; that it lives in a child or different context from the injecting bean; or that it is marked autowireCandidate = false or defaultCandidate = false (check your version for the latter).
Why this question is asked
This bug is confusing because every obvious check passes: the class has @Component, it is in a scanned package, and its constructor even logs a message at startup. Yet the handler never receives events. Interviewers like this question because the answer requires knowing what Spring checks after creating a bean, which is different from what it checks to create it. In this answer, we will recap how a collection is filled, then go through each cause with a way to reproduce it, and finish with a quick way to find out which one we are facing.
1A Quick Recap: Created Is Not the Same as Matched
To fill List<EventHandler>, Spring asks the context for every bean that is a candidate for that injection point. A bean is a candidate only if its type, as the container knows it, is assignable to the requested type including generics, it is visible from the injecting bean's context, and it has not been excluded from autowiring.
The constructor log only proves the first step, that something created an instance of the class. It might be the container creating a bean that later fails one of those checks, or it might even be a second context creating its own copy. So the question becomes: which check does our bean fail?
2Cause 1: The Bean Is Not an EventHandler Any More
After a bean is created, BeanPostProcessors may replace it with a proxy, a wrapper object generated at runtime. The bean in the container is then the proxy, and its type is whatever the proxy implements. Spring Boot's class-based proxies subclass the class, so they keep every interface. But a JDK dynamic proxy created for a chosen list of interfaces, by a custom post-processor or a library, may not include EventHandler.
Notice the last line: the bean exists under its name, but it is no longer an EventHandler. The fix is to proxy all of the target's interfaces, or to use class-based proxies with ProxyFactory and setProxyTargetClass(true). A similar effect appears when a @Bean method declares a narrower return type than the object it returns, because Spring uses the declared type for matching before the bean is created.
3Cause 2: The Generic Type Does Not Match
Spring compares generic type parameters when it matches beans to an injection point. A list declared as List<EventHandler<OrderEvent>> receives only handlers declared for OrderEvent.
This is correct behaviour, but easy to forget when the handler implements a subtype or a different event, or when a lambda-based @Bean hides its generic type: a @Bean method declared as returning raw EventHandler gives Spring less information than one declared as EventHandler<OrderEvent>. We check the generic declaration on both sides.
4Cause 3: It Lives in Another Context
Collection injection includes beans from the injecting bean's own context and its parent contexts, but never from a child or sibling context. In a classic Spring MVC application, a handler scanned by the servlet context is invisible to a dispatcher defined in the root context. In tests, a slice like @WebMvcTest or a separate context built for one test class may create the handler in a context the dispatcher does not belong to. The handler's constructor still logs, because its own context created it.
4 messages in order. Play them, or step through them one at a time.
Lookups go up the hierarchy, never down.
5Cause 4: It Is Excluded From Autowiring
A bean definition can opt out of being injected by type. autowireCandidate = false removes it from all autowiring: the bean exists and can be fetched by name, but no injection point, single or collection, receives it. Spring Framework 6.2 added defaultCandidate = false, which keeps a bean out of injection points that do not use a qualifier; it is meant for beans that should be injected only when asked for explicitly (check your version for its exact behaviour with collections).
These settings are often set deliberately in shared configuration and then forgotten, so we search the configuration, including XML and any BeanFactoryPostProcessor that changes definitions, for them.
6Finding the Cause Quickly
A few lines in a test or a debugger narrow it down in minutes. ctx.getBeansOfType(EventHandler.class) shows whether the context considers the bean an EventHandler at all; if it is missing there, look at proxies and the declared type. ctx.getBean("auditHandler").getClass() shows whether it is a proxy. ResolvableType comparison or simply changing the list to EventHandler<?> shows whether generics are the problem. ctx.getBeanFactory().getBeanDefinition("auditHandler").isAutowireCandidate() reveals an exclusion. And if getBean("auditHandler") fails in the dispatcher's context while the log shows the constructor, the bean is in another context.
One more possibility is worth a quick look: the constructor message might come from an instance that someone creates with new, for example in a factory or a test, which was never a Spring bean in the first place.
- Found by getBean("auditHandler") in this context?YesNext checkNoAnother context, or not a bean: check contexts
- Is the bean an instance of EventHandler?YesNext checkNoProxy or declared type hides it
- Does the list's generic type match the bean's?YesNext checkNoFix generics on either side
- isAutowireCandidate() true?YesLook at qualifiers on the listNoExcluded: autowireCandidate or defaultCandidate
4 steps in order. Play them, or step through them one at a time.
7Follow-up questions
Could @Order or @Conditional cause a handler to be missing?
@Order cannot remove a bean, it only changes the position. A condition could prevent the bean from being registered, but then its constructor would not run, which our symptom rules out, unless a second context without that condition created it. If the constructor logs twice, we have two contexts or a manual new.
Why would a qualifier on the list hide a handler?
A qualifier on the injection point, @Qualifier("sync") List<EventHandler>, filters the collection to beans with that qualifier. Someone may have added it to select a subset, and new handlers without the qualifier are then silently left out. It is worth checking the injection point as carefully as the bean.
How can we stop this from happening again?
Add a startup check or a test that asserts the expected handlers are present, for example comparing the injected list's classes with the set of classes annotated with a custom @HandlesEvent annotation. A dispatcher that logs its handlers at startup, by class and order, also makes a missing one visible on the first run.
8Conclusion
In this answer, we saw that a constructor message only proves an instance was created, not that the bean matches List<EventHandler>. The bean may have been replaced by a proxy that does not implement EventHandler, its generic type may not match the list's, it may live in a child or different context that the injecting bean cannot see, or it may be excluded with autowireCandidate = false or defaultCandidate = false. A few container queries, getBeansOfType, the bean's class, a wildcard generic and isAutowireCandidate, tell us which in minutes.
Open with
The constructor log tells me an instance was created, but to be in the list the bean must also be a candidate: its type as the container sees it must match EventHandler including generics, it must be visible from the injecting bean's context, and it must not be excluded from autowiring.
Then, if they want more
So I check four things. First, the type after post-processing. If a BeanPostProcessor replaced it with a JDK proxy built only for some other interface, the bean in the container is no longer an EventHandler; getBean by name and an instanceof check shows that. A @Bean method with a narrower declared return type has a similar effect. Second, generics.
If the list is List of EventHandler of OrderEvent and the handler is EventHandler of PaymentEvent, or its @Bean method returns a raw type, it does not match; switching to a wildcard quickly confirms it. Third, the context.
Collection injection includes the bean's own context and its parents, never children or siblings, so a handler scanned by a servlet context or created in a separate test context is invisible to a dispatcher in the root context, even though its constructor ran.
Fourth, exclusion: autowireCandidate false removes it from all autowiring, and since 6.2 defaultCandidate false keeps it out of unqualified injection points. I would also check for a qualifier on the list, and whether the log comes from a manual new.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A class injects List<EventHandler> but one handler is missing from the list. Its class...": https://scrivio-interview-library.netlify.app/spring-boot/dependency-injection/30f7c645cc/