Skip to content

@RestControllerAdvice @ExceptionHandler Inconsistent behavior with @RestControllerEndpoint #31495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

terminux
Copy link
Contributor

Hi, I submitted this PR to solve #30899 based on @wilkinsona ’s comment.

When I switched to BeanFactoryUtils.beansOfTypeIncludingAncestors, I found that still can't solve the problem, this is because the bean names of org.springframework.boot.actuate.autoconfigure.web.servlet.CompositeHandlerExceptionResolver and org.springframework.web.servlet.handler.HandlerExceptionResolverComposite are the same.

  • See WebMvcEndpointChildContextConfiguration.java#L100-L101

@Bean(name = DispatcherServlet.HANDLER_EXCEPTION_RESOLVER_BEAN_NAME)
CompositeHandlerExceptionResolver compositeHandlerExceptionResolver() {


So when using BeanFactoryUtils.beansOfTypeIncludingAncestors, HandlerExceptionResolverComposite will be overwritten by CompositeHandlerExceptionResolver.


Maybe we need a variant of BeanFactoryUtils.beansOfTypeIncludingAncestors, use collection to collect HandlerExceptionResolver instead of map, or modify the bean name of CompositeHandlerExceptionResolver, I chose the former for now.

Closes gh-30899

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 22, 2022
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 22, 2022
@philwebb philwebb added this to the 2.6.x milestone Jun 22, 2022
@philwebb philwebb self-assigned this Jun 22, 2022
@philwebb philwebb modified the milestones: 2.6.x, 2.6.9 Jun 22, 2022
philwebb pushed a commit that referenced this pull request Jun 22, 2022
Update `CompositeHandlerExceptionResolver` to search for beans in
all contexts. Note that `BeanFactoryUtils.beansOfTypeIncludingAncestors`
cannot not be used since we need to pick up all beans, even if they
have the same name.

See gh-31495
philwebb added a commit that referenced this pull request Jun 22, 2022
@philwebb philwebb closed this in 7017e10 Jun 22, 2022
@philwebb
Copy link
Member

Thanks @terminux, this has now been merged to 2.6.x and forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants