Skip to content

Add @Interceptor annotation to make HandlerInterceptors easier to register #40360

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
lukalomidze opened this issue Apr 15, 2024 · 5 comments
Closed
Labels
for: external-project For an external project and not something we can fix status: declined A suggestion or change that we don't feel we should currently apply

Comments

@lukalomidze
Copy link

It feels like there should be an @Interceptor annotation the way that spring has @Service, @Repository, etc. I think it would be a good idea to include such an annotation with values equivalent to .addPathPatterns, .excludePathPatterns, maybe something like order to facilitate chaining and so on and have spring boot auto config take care of registering it instead of having to create a WebMvcConfigurer

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

I'm not sure exactly what you're trying to do, but perhaps @ControllerAdvice or @RestControllerAdvice might be helpful? If not, please open a new issue at https://github.com/spring-projects/spring-framework/ with some more details so that they can consider the idea.

@philwebb philwebb closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
@philwebb philwebb added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 15, 2024
@lukalomidze
Copy link
Author

lukalomidze commented Apr 16, 2024

The idea is that in spring boot spirit, i.e minimal manual configuration, it would be nice to have an @Interceptor annotation that would take care of registering an annotated interceptor it in InterceptorRegistry

@philwebb
Copy link
Member

Given that the HandlerInterceptor beans aren't all that common, I'm not sure that we should add an additional annotation.

I guess you're looking for something like this:

@Interceptor(pathPatterns="/foo/*")
class MyInterceptor implements HandlerInterceptor {
   ...
}

Which is a little more concise than:

@Bean
public WebMvcConfigurer myConfigurer() {
	return new WebMvcConfigurer() {

		@Override
		public void addInterceptors(InterceptorRegistry registry) {
			registry.addWebRequestInterceptor(new MyInterceptor()).addPathPatterns("/foo/*");
		}

	};
}

This still feels like a Spring Framework feature to me, especially as the @Controller annotations are there.

I'll flag this one for team-attention to see what other folks in the team think.

@philwebb philwebb reopened this Apr 16, 2024
@philwebb philwebb added for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged and removed for: external-project For an external project and not something we can fix labels Apr 16, 2024
@philwebb philwebb changed the title @Interceptor annotation Add @Interceptor annotation to make HandlerInterceptors easier to register Apr 16, 2024
@wilkinsona
Copy link
Member

This feels like a Spring Framework issue to me too. I don't think we should have a Boot-specific annotation for automatic registration of Framework's HandlerInterceptor contract.

@bclozel
Copy link
Member

bclozel commented Apr 16, 2024

Thanks for the proposal, but this is indeed a Spring Framework enhancement request. This was already requested and declined in the past. In the meantime, there is less focus on the HandlerInterceptor contract these days.

Closing as a duplicate of spring-projects/spring-framework#9447

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Apr 16, 2024
@bclozel bclozel added status: declined A suggestion or change that we don't feel we should currently apply for: external-project For an external project and not something we can fix and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

5 participants