Skip to content

Create multiple registrations for beans that implement multiple Servlet API contracts #39056

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
michaldo opened this issue Jan 8, 2024 · 1 comment
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@michaldo
Copy link
Contributor

michaldo commented Jan 8, 2024

When a class is together filter and listener, for example
@Component class Together implements Filter, ServletRequestListener, it is only filter, not a listener.
The reason in org.springframework.boot.web.servlet.ServletContextInitializerBeans#seen;
if something is registered as filter, it became seen and cannot be registered as listener

That is not natural, because

  1. Implementing one interface does not invalidate other. If developer decides that one beans serves for 2 purposes, it must be accepted or rejected as a bug
  2. For tracing scenario it is natural, that tracing starts when tracing header is available and lasts until request is destroyed. So closing tracing code in single class is natural choice

It it not a big problem and workaround is easy, but it seems to be an inconsistency bug

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 8, 2024
@wilkinsona
Copy link
Member

Thanks for the report. Things have been this way since 1.1 (if not earlier) so I think we may need to tread a little carefully when changing the behaviour in case doing so has unwanted side effects. I think it may be better to treat this as an enhancement, particularly as there's a workaround, and add support for beans that implement more the one contract from the Servlet API being registered multiple times in 3.3.

@wilkinsona wilkinsona changed the title Bean can't be a Filter and ServletRequestListener together Create multiple registrations for beans that implement multiple Servlet API contracts Jan 8, 2024
@wilkinsona wilkinsona added the for: team-meeting An issue we'd like to discuss as a team to make progress label Jan 8, 2024
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Jan 15, 2024
@wilkinsona wilkinsona added this to the 3.3.x milestone Jan 15, 2024
mhalbritter added a commit to mhalbritter/spring-boot that referenced this issue Jan 17, 2024
@mhalbritter mhalbritter self-assigned this Jan 17, 2024
@mhalbritter mhalbritter modified the milestones: 3.3.x, 3.3.0-M1 Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants