Reputation: 6784
I have a controller with request mapping as @RequestMapping("/**")
What does it mean?
If I want to exclude certain url pattern from the above mapping how would I do that?
Could someone please shed some light on it?
Upvotes: 10
Views: 40518
Reputation: 156
Your URL will intercept all requests matching '/**'. Depending on where you are defining this I am not sure why you would want to do this. On class level this should define the base path while on method level it should be refined to the specific function.
If you would like to exclude a pattern you could define another controller that is ordered at a higher priority to the controller specifying '/**'
Here are 2 good references from spring source:
Upvotes: 8
Reputation: 761
I was able to achieve "url exclusion" or "not matching url" through the use of the Regex "negative lookahead" construct.
I want my handler to handel everything other than static resources, i.e. CSS/Images/JS, and error pages.
To prevent that handeling of error pages i.e. resourceNotFound you will need to
In your controller use the below
@Controller
@RequestMapping(value = { "/" })
public class CmsFrontendController {
@RequestMapping(value = { "/" }, headers = "Accept=text/html")
public String index(Model ui) {
return addMenu(ui, "/");
}
@RequestMapping(value = { "{path:(?!resources|error).*$}", "{path:(?!resources|error).*$}/**" }, headers = "Accept=text/html")
public String index(Model ui, @PathVariable(value = "path")String path) {
try {
path = (String) request.getAttribute(
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
return addMenu(ui, path);
} catch (Exception e) {
log.error("Failed to render the page. {}", StackTraceUtil.getStackTrace(e));
return "error/general";
}
}
}
Upvotes: 16