Hi, I do something in order to @WebFilter support @Order here

But, due to

private void org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ListableBeanFactory beanFactory)

protected  Servlet org.springframework.boot.web.servlet.ServletRegistrationBean.getServlet()

protected String org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean.getTargetBeanName()

method access privilege,implement are not elegant。

So,method access privilege above this method, can public or protect。

Comment From: wilkinsona

In my opinion, supporting @Order on @WebFilter doesn't really gain you very much. The former is a Spring concept and the latter is from the Servlet API. The Servlet spec doesn't provide a way to order filters when they're registered using annotations. Spring Boot's support for @WebFilter is in line with that.

If you are in a position to annotate your class with @Order then you're also in a position to use @Component rather than @WebFilter. At that point ordering will be supported as you've indicated that it's a Spring-managed component so the concept of ordering makes sense.

Can you please describe that problem that you're trying to solve, rather than the difficulty that you're having in solving it?

Comment From: sdcuike

I want order filter ,but not implement this:https://github.com/sdcuike/spring-boot-practice/blob/master/src/main/java/com/sdcuike/practice/web2/WebComponent2Config.java

Comment From: wilkinsona

Thanks. Just to confirm, you want to use @WebFilter because it lets you configure the filter without using FilterRegistrationBean and you also want to control the order?

Comment From: sdcuike

yes,thanks

Comment From: chainkite

+1, as @Component cannot support urlPatterns in @WebFilter

Comment From: philwebb

@chainkite You can configure urlPatterns using a FilterRegistrationBean

Comment From: philwebb

I don't think that we should support @Order with @WebFilter. As @wilkinsona mentioned the Servlet spec doesn't provide a way to order filters and I don't think we should support something that works in the embedded mode but not when deployed to a regular servlet container.

Comment From: wilkinsona

I don't think we should support something that works in the embedded mode but not when deployed to a regular servlet container

That's a very compelling argument not to do this. I think the confusion that would cause greatly outweighs the few lines of code that it would save.

Comment From: sdcuike

Thanks for answer

Comment From: hongsir

thank you very much!

Comment From: fssrepository

What about this?

@WebFilter(Constants.FORM_BASE + "/login/check")
public class LoginFilter extends UsernamePasswordAuthenticationFilter {

Comment From: profitgsilva

Oops, by default the filters are sorted alphabetically. So it's possible to do it this way using @WebFilter.

@WebFilter(urlPatterns={"/AAA/*" })
public class FilterA implements Filter {
        ...
}
@WebFilter(urlPatterns={"/BBB/*" })
public class FilterB implements Filter {
        ...
}

In this way FilterA takes precedence over FilterB