Issue
I'm trying to use filter for centain url in Spring. When i use it like this:
registrationBean.addUrlPatterns("/api/user/*");
It's work for all url that starts with "/api/user"
registrationBean.addUrlPatterns("/api/user/*/activate");
It didn't work for "/api/user/607a7244-3db9-429a-89f0-1662da0b0e15/activate"
I checked it on the documentation here,
they said:
* matches zero or more characters
Anyone know why "/api/user/*/activate" not match with "/api/user/607a7244-3db9-429a-89f0-1662da0b0e15/activate"?
Solution
You are trying to register a filter using the FilterRegistrationBean
. As this is a Filter
being registered the URL mapping relies on the support of the servlet container not the support in Spring (Boot).
URL mapping of the servlet container is determined by what is specified in the servlet specification (See section 12.2). Which is also mentioned in the javadoc of the addUrlPatterns
method.
The URL mapping in the servlet specification is very basic and is only matching the first part of the URL. So that is why your first, /api/user/*
works (as the URL starts with /api/user
but not /api/user/*/activate
because it doesn't start with /api/user/*/activate
. It isn't ant-style expression just a simple pattern for the start of a URL.
Answered By - M. Deinum
Answer Checked By - Marilyn (JavaFixing Volunteer)