{"id":796,"date":"2013-10-22T04:26:09","date_gmt":"2013-10-22T11:26:09","guid":{"rendered":"http:\/\/10kdev.net\/?p=796"},"modified":"2013-10-22T04:34:58","modified_gmt":"2013-10-22T11:34:58","slug":"spring-mvc-beat-me-down-with-a-404","status":"publish","type":"post","link":"http:\/\/10kdev.net\/?p=796","title":{"rendered":"Spring MVC beat me down with a 404"},"content":{"rendered":"<p>Before I get started on this, here is the solution I chose for setting up a 404 error trap in a Spring Web MVC (Spring 3.2). It may seem old school, but after hours of research and testing this is what works the best for my application.<\/p>\n<p><strong>Solution<br \/> <\/strong><\/p>\n<p>In web.xml add something like this, you r location could be an html page but mine is an error controller endpoint:<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: teal;\">&lt;<span style=\"color: #3f7f7f;\">error-page<span style=\"color: teal;\">&gt;<\/span><br \/> <\/span><\/span><\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: teal;\">&lt;<span style=\"color: #3f7f7f;\">error-code<span style=\"color: teal;\">&gt;<span style=\"color: black;\">404<span style=\"color: teal;\">&lt;\/<span style=\"color: #3f7f7f;\">error-code<span style=\"color: teal;\">&gt;<\/span><br \/> <\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: teal;\">&lt;<span style=\"color: #3f7f7f;\">location<span style=\"color: teal;\">&gt;<span style=\"color: black;\">\/error\/404<span style=\"color: teal;\">&lt;\/<span style=\"color: #3f7f7f;\">location<span style=\"color: teal;\">&gt;<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: black;\"><span style=\"font-family: Consolas; font-size: 10pt;\"> <span style=\"color: teal;\">&lt;\/<span style=\"color: #3f7f7f;\">error-page<span style=\"color: teal;\">&gt;<\/span><\/span><\/span><\/span><br \/> <\/span><\/p>\n<p>My error controller looks like this, in my case I return an error object that has a status and message property that gets deserialized to json:<\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: #646464; font-family: Consolas; font-size: 10pt;\">@Api<span style=\"color: black;\">(description = <span style=\"color: #2a00ff;\">&#8220;Error Controller to catch errors not covered by ControllerAdvice.&#8221;<span style=\"color: black;\">, value = <span style=\"color: #2a00ff;\">&#8220;\/error&#8221;<span style=\"color: black;\">)<\/span><br \/> <\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: #646464; font-family: Consolas; font-size: 10pt;\">@<span style=\"color: black; text-decoration: underline;\">Controller<\/span><br \/> <\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: #646464; font-family: Consolas; font-size: 10pt;\">@RequestMapping<span style=\"color: black;\">(value = <span style=\"color: #2a00ff;\">&#8220;\/error&#8221;<span style=\"color: black;\">, produces = MediaType.<span style=\"color: #0000c0;\"><em>APPLICATION_JSON_VALUE<\/em><span style=\"color: black;\">)<\/span><br \/> <\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: #7f0055; font-family: Consolas; font-size: 10pt;\"><strong>public<\/strong><span style=\"color: black;\"><br \/> <span style=\"color: #7f0055;\"><strong>class<\/strong><span style=\"color: black;\"> ErrorController {<\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #646464;\">@RequestMapping<span style=\"color: black;\">(value=<span style=\"color: #2a00ff;\">&#8220;\/404&#8221;<span style=\"color: black;\">)<\/span><br \/> <\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"><br \/> <span style=\"color: #646464;\">@ResponseStatus<span style=\"color: black;\">(HttpStatus.<span style=\"color: #0000c0;\"><em>NOT_FOUND<\/em><span style=\"color: black;\">)<\/span><br \/> <\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"><br \/> <span style=\"color: #646464;\">@ApiOperation<span style=\"color: black;\">(value = <span style=\"color: #2a00ff;\">&#8220;404 Error Handler&#8221;<span style=\"color: black;\">)<\/span><br \/> <\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"><br \/> <span style=\"color: #7f0055;\"><strong>public<\/strong><span style=\"color: black;\"><br \/> <span style=\"color: #646464;\">@ResponseBody<span style=\"color: black;\"> ControllerResponse unmappedRequest(HttpServletResponse response) <span style=\"color: #7f0055;\"><strong>throws<\/strong><span style=\"color: black;\"> IOException {<\/span><br \/> <\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0<span style=\"color: #7f0055;\"><strong>return<\/strong><span style=\"color: black;\"><br \/> <span style=\"color: #7f0055;\"><strong>new<\/strong><span style=\"color: black;\"> ControllerResponse.Builder().status(ControllerResponseEnum.<span style=\"color: #0000c0;\"><em>error<\/em><span style=\"color: black;\">).message(HttpStatus.<span style=\"color: #0000c0;\"><em>NOT_FOUND<\/em><span style=\"color: black;\">.getReasonPhrase()).build();<\/span><br \/> <\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"font-family: Consolas; font-size: 10pt;\"><span style=\"color: black;\"> }<\/span><br \/> <\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">}<br \/> <\/span><\/p>\n<p><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">ControllerReponse is just a simple json pojo<br \/> <\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: #646464; font-family: Consolas; font-size: 10pt;\">@JsonInclude<span style=\"color: black;\">(Include.<span style=\"color: #0000c0;\"><em>NON_NULL<\/em><span style=\"color: black;\">)<\/span><br \/> <\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: #7f0055; font-family: Consolas; font-size: 10pt;\"><strong>public<\/strong><span style=\"color: black;\"><br \/> <span style=\"color: #7f0055;\"><strong>class<\/strong><span style=\"color: black;\"> ControllerResponse {<\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #646464;\">@JsonProperty<\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #646464;\">@JsonFormat<span style=\"color: black;\">(shape = <span style=\"color: #646464;\">JsonFormat<span style=\"color: black;\">.Shape.<span style=\"color: #0000c0;\"><em>STRING<\/em><span style=\"color: black;\">)<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #7f0055;\"><strong>private<\/strong><span style=\"color: black;\"> ControllerResponseEnum <span style=\"color: #0000c0;\">status<span style=\"color: black;\">;<\/span><br \/> <\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"><br \/> <span style=\"color: #646464;\">@JsonProperty<\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #7f0055;\"><strong>private<\/strong><span style=\"color: black;\"> String <span style=\"color: #0000c0;\">data<span style=\"color: black;\">;<\/span><br \/> <\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"><br \/> <span style=\"color: #646464;\">@JsonProperty<\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #7f0055;\"><strong>private<\/strong><span style=\"color: black;\"> String <span style=\"color: #0000c0;\">meta<span style=\"color: black;\">;<\/span><br \/> <\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"><br \/> <span style=\"color: #646464;\">@JsonProperty<\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black;\"><span style=\"font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #7f0055;\"><strong>private<\/strong><span style=\"color: black;\"> String <span style=\"color: #0000c0;\">message<span style=\"color: black;\">;<\/span><\/span><\/span><\/span><\/span><br \/> <\/span><\/p>\n<p style=\"margin-left: 36pt;\"><em> \u2026. Plus getters\/setters etc. . . .<br \/> <\/em><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">ControllerResponseEnum simply lists the values suggested in the <a href=\"http:\/\/labs.omniti.com\/labs\/jsend\">JSend<\/a> spec: success, fail, or error.<br \/> <\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: #7f0055; font-family: Consolas; font-size: 10pt;\"><strong>public<\/strong><span style=\"color: black;\"><br \/> <span style=\"color: #7f0055;\"><strong>enum<\/strong><span style=\"color: black;\"> ControllerResponseEnum {<br \/> <\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0<span style=\"color: #0000c0;\">success, fail, error<span style=\"color: black;\"><em><br \/> <\/em><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"font-family: Consolas; font-size: 10pt;\"><span style=\"color: black;\">}<\/span><br \/> <\/span><\/p>\n<p><strong>Things That Didn&#8217;t Work For Me \u2013 406&#8217;s everywhere<\/strong><\/p>\n<p><strong><em>Special controller mapped to \/** didn&#8217;t work<\/em><\/strong><\/p>\n<p>At first I thought I could just create an error controller and catch everything coming in at \/** by adding a request mapping and throw the error from there, centralizing my error responses. This works great like this . . . (but . . . )<span style=\"color: black; font-family: Consolas; font-size: 10pt;\"><br \/> <\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"><br \/> <span style=\"color: #646464;\"><strong><span style=\"background-color: yellow;\">@RequestMapping<span style=\"color: black;\">(value=<span style=\"color: #2a00ff;\">&#8220;\/**&#8221;<span style=\"color: black;\">)<\/span><\/span><\/span><\/span><\/strong><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #646464;\">@ResponseStatus<span style=\"color: black;\">(HttpStatus.<span style=\"color: #0000c0;\"><em>NOT_FOUND<\/em><span style=\"color: black;\">)<\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #646464;\">@ApiOperation<span style=\"color: black;\">(value = <span style=\"color: #2a00ff;\">&#8220;404 Error Handler&#8221;<span style=\"color: black;\">)<\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #7f0055;\"><strong>public<\/strong><span style=\"color: black;\"><br \/> <span style=\"color: #646464;\">@ResponseBody<span style=\"color: black;\"> ControllerResponse unmappedRequest(HttpServletResponse response) <span style=\"color: #7f0055;\"><strong>throws<\/strong><span style=\"color: black;\"> IOException {<\/span><br \/> <\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">The good thing is \u2013 it intercepts EVERYTHING. The bad thing is \u2013 it intercepts EVERYTHING. So I ran into problems with my static resource files. There&#8217;s a schema and some ui on the path needed for the ReST application:<br \/> <\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0<span style=\"color: teal;\">&lt;<span style=\"color: #3f7f7f;\">mvc:resources\u00a0<\/span><span style=\"color: #7f007f; font-size: 10pt;\">mapping<\/span><span style=\"color: black;\">=<span style=\"color: #2a00ff;\"><em>&#8220;\/static\/**&#8221;\u00a0<\/em><\/span><\/span><span style=\"color: #7f007f;\"><span style=\"color: black;\"><span style=\"color: #7f007f;\">location<span style=\"color: black;\">=<span style=\"color: #2a00ff;\"><em>&#8220;\/static\/&#8221;\u00a0<\/em><\/span><span style=\"color: teal; font-size: 10pt;\">\/&gt;<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p>But the &#8220;\/**&#8221; controller wreaks havoc. I tried everything under the sou to get this to work: writing redirects in the error controller for instance, some fancy web.xml default servlet mappings. Nothing. It throws out 406 errors (NOT ACCEPTABLE error).<\/p>\n<p><strong><em>Interceptors require too much code to maintain, comparatively to the solution I needed<\/em><\/strong><\/p>\n<p>Even tried configuring an intercept filter and handle the code there, but I started to write waaaaaay tooo much.<\/p>\n<p><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0<span style=\"color: teal;\">&lt;<span style=\"color: #3f7f7f;\">mvc:interceptors<span style=\"color: teal;\">&gt;<\/span><br \/> <\/span><\/span><\/span><\/p>\n<p><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: teal;\">&lt;<span style=\"color: #3f7f7f;\">mvc:interceptor<span style=\"color: teal;\">&gt;<\/span><br \/> <\/span><\/span><\/span><\/p>\n<p><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: teal;\">&lt;<span style=\"color: #3f7f7f;\">mvc:mapping\u00a0<\/span><span style=\"color: #7f007f; font-size: 10pt;\">path<\/span><span style=\"color: black;\">=<span style=\"color: #2a00ff;\"><em>&#8220;\/**&#8221;\u00a0<\/em><\/span><\/span><span style=\"color: #7f007f;\"><span style=\"color: black;\"><span style=\"color: teal;\">\/&gt;<\/span><br \/> <\/span><\/span><\/span><\/span><\/p>\n<p><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: teal;\">&lt;<span style=\"color: #3f7f7f;\">bean\u00a0<\/span><span style=\"color: #7f007f; font-size: 10pt;\">class<\/span><span style=\"color: black;\">=<span style=\"color: #2a00ff;\"><em>&#8220;com.ist.common.error.StaticContentInterceptor&#8221;<\/em><\/span><\/span><span style=\"color: #7f007f;\"><span style=\"color: black;\"><span style=\"color: teal;\">\/&gt;<\/span><br \/> <\/span><\/span><\/span><\/span><\/p>\n<p><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: teal;\">&lt;\/<span style=\"color: #3f7f7f;\">mvc:interceptor<span style=\"color: teal;\">&gt;<\/span><br \/> <\/span><\/span><\/span><\/p>\n<p><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0<span style=\"color: teal;\">&lt;\/<span style=\"color: #3f7f7f;\">mvc:interceptors<span style=\"color: teal;\">&gt;<br \/> <\/span><\/span><\/span><\/span><\/p>\n<p><span style=\"color: teal; font-family: Consolas; font-size: 10pt;\"><span style=\"color: #000000;\">Or try it with java config file:<\/span><br \/> <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"font-family: Consolas; font-size: 10pt;\"><span style=\"color: #646464;\">@Configuration<\/span><br \/> <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"font-family: Consolas; font-size: 10pt;\"><span style=\"color: #646464;\">@EnableWebMvc<\/span><br \/> <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #7f0055; font-family: Consolas; font-size: 10pt;\"><strong>public<\/strong><span style=\"color: black;\"><br \/> <span style=\"color: #7f0055;\"><strong>class<\/strong><span style=\"color: black;\"> StaticContentConfig <span style=\"color: #7f0055;\"><strong>extends<\/strong><span style=\"color: black;\"> WebMvcConfigurerAdapter {<\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #3f7f5f;\">\/\/@formatter:off<\/span><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #646464;\">@Override<\/span><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #7f0055;\"><strong>public<\/strong><span style=\"color: black;\"><br \/> <span style=\"color: #7f0055;\"><strong>void<\/strong><span style=\"color: black;\"> addInterceptors(InterceptorRegistry registry) {<\/span><br \/> <\/span><\/span><\/span><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0registry.addInterceptor(<span style=\"color: #7f0055;\"><strong>new<\/strong><span style=\"color: black;\"><br \/> <span style=\"background-color: lightgrey;\">StaticContentInterceptor<\/span>())<\/span><br \/> <\/span><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.addPathPatterns(<span style=\"color: #2a00ff;\">&#8220;\/**&#8221;<span style=\"color: black;\">) }<\/span><\/span><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: #3f7f5f;\">\/\/@formatter:on<\/span><br \/> <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\">}<br \/> <\/span><\/p>\n<p>Nope.<\/p>\n<p><strong><em>MIME type mappings \u2013 might as well just do &lt;error&gt; config if you are messing with web.xml:<\/em><\/strong><\/p>\n<p>How about mounting every freakin static mime type . . . .<\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: maroon; font-family: Consolas; font-size: 10pt;\">&lt;servlet-mapping&gt;<\/span><\/p>\n<p style=\"margin-left: 36pt; padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: maroon;\">&lt;servlet-name&gt;<span style=\"color: black;\">MyApp<span style=\"color: maroon;\">&lt;\/servlet-name&gt;<\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt; padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: maroon;\">&lt;url-pattern&gt;<span style=\"color: black;\">\/<span style=\"color: maroon;\">&lt;\/url-pattern&gt;<\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: maroon; font-family: Consolas; font-size: 10pt;\">&lt;\/servlet-mapping&gt;<\/span><\/p>\n<p style=\"margin-left: 36pt; padding-left: 30px;\"><span style=\"color: maroon; font-family: Consolas; font-size: 10pt;\"><span style=\"color: black;\"> <span style=\"color: gray;\">&lt;!&#8211; The &#8216;dynamic&#8217; content &#8211;&gt;<\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: maroon; font-family: Consolas; font-size: 10pt;\">&lt;servlet-mapping&gt;<\/span><\/p>\n<p style=\"margin-left: 36pt; padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: maroon;\">&lt;servlet-name&gt;<span style=\"color: black;\">default<span style=\"color: maroon;\">&lt;\/servlet-name&gt;<\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt; padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: maroon;\">&lt;url-pattern&gt;<span style=\"color: black;\">*.css<span style=\"color: maroon;\">&lt;\/url-pattern&gt;<span style=\"color: black;\"><br \/> <\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: maroon; font-family: Consolas; font-size: 10pt;\">&lt;\/servlet-mapping&gt;<span style=\"color: black;\"><br \/> <\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: maroon; font-family: Consolas; font-size: 10pt;\">&lt;servlet-mapping&gt;<\/span><\/p>\n<p style=\"margin-left: 36pt; padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: maroon;\">&lt;servlet-name&gt;<span style=\"color: black;\">default<span style=\"color: maroon;\">&lt;\/servlet-name&gt;<\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt; padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: maroon;\">&lt;url-pattern&gt;<span style=\"color: black;\">*.js<span style=\"color: maroon;\">&lt;\/url-pattern&gt;<span style=\"color: black;\"><br \/> <\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: maroon; font-family: Consolas; font-size: 10pt;\">&lt;\/servlet-mapping&gt;<span style=\"color: black;\"><br \/> <\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: maroon; font-family: Consolas; font-size: 10pt;\">&lt;servlet-mapping&gt;<\/span><\/p>\n<p style=\"margin-left: 36pt; padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: maroon;\">&lt;servlet-name&gt;<span style=\"color: black;\">default<span style=\"color: maroon;\">&lt;\/servlet-name&gt;<\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt; padding-left: 30px;\"><span style=\"color: black; font-family: Consolas; font-size: 10pt;\"> <span style=\"color: maroon;\">&lt;url-pattern&gt;<span style=\"color: black;\">*.jpg<span style=\"color: maroon;\">&lt;\/url-pattern&gt;<span style=\"color: black;\"><br \/> <\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"margin-left: 36pt;\"><span style=\"color: maroon; font-family: Consolas; font-size: 10pt;\">&lt;\/servlet-mapping&gt;<span style=\"color: black;\"><br \/> <span style=\"color: gray;\">&lt;!&#8211; The &#8216;static&#8217; content &#8211;&gt;<span style=\"color: black;\"><br \/> <\/span><\/span><\/span><\/span><\/p>\n<p>The 404 isn&#8217;t a Spring MVC issue. The error is scoped outside of the framework. By the time you get there, you&#8217;ve passed up a lot of other functionality. Here are some key conversations about the issue that had me settle on what I put in:<\/p>\n<p><a href=\"https:\/\/jira.springsource.org\/browse\/SPR-8837\">https:\/\/jira.springsource.org\/browse\/SPR-8837<\/a><\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/11792231\/spring-mvc-catch-http-errors-400-404\">http:\/\/stackoverflow.com\/questions\/11792231\/spring-mvc-catch-http-errors-400-404<\/a><\/p>\n<p>So I guess what burned me is that a 404 is a basic error of doing web applications, and I just don&#8217;t like having more than one way to do things if I can help it. I handle 500 errors via the framework, so why not 404&#8217;s? The solution makes sense for now, as the simplest. Of course you could write a log of code in the interceptor or controller \/** method, but that (IMHO) defeats the purpose of convention over a coded configuration. Since I was left to configuration, I just chose the simplest path.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before I get started on this, here is the solution I chose for setting up a 404 error trap in a Spring Web MVC (Spring 3.2). It may seem old school, but after hours of research and testing this is what works the best for my application. Solution In web.xml add something like this, you [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/796"}],"collection":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=796"}],"version-history":[{"count":4,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/796\/revisions"}],"predecessor-version":[{"id":800,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/796\/revisions\/800"}],"wp:attachment":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=796"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}