Skip to content

@ControllerAdvice not detected from parent contexts (even though @Controller is) [SPR-11570] #16194

@spring-projects-issues

Description

@spring-projects-issues

stripybadger opened SPR-11570 and commented

I use ContextLoaderListener to load most of my spring stuff (lets call this context P), then have a DispatcherServlet. Each DispatcherServlet creates its own application context (lets call this D) which gets parented by P.

If I have beans in P which are controllers (annotated with @Controller), they still get exposed by the DispatcherServlet. However any ControllerAdvice beans in P do not get picked up.

I think this inconsistency is a bug. Particularly as many users will want to be able to share controller advice beans between DispatcherServlet (e.g. it may be useful to share exception handling across all servlets).

See AbstractDetectingUrlHandlerMapping:74 - calls BeanFactoryUtils.beanNamesForTypeIncludingAncestor
ControllerAdviceBean:92 - calls applicationContext.getBeanDefinitionNames() (which only appears to get beans from the current context, not parents)


Affects: 3.2.3

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions