I'm using Spring boot (1.2.2) and I'm trying to send a png file as response. On my IDE (IntelliJ) it works perfect, but when deploying to tomcat I'm getting the following message for url http://example.com/myWebapp/files/17.png
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.
When I open catalina log I see this:
o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/myWebapp/files/18.png] in DispatcherServlet with name 'dispatcherServlet'
MyService.java:
@RestController
public class MyService {
@RequestMapping(value = "/files/{file_name:.+}", method = RequestMethod.GET)
public void getFile(@PathVariable("file_name") String fileName, HttpServletResponse response) {
InputStream is = null;
try {
is = session().getFileServer().getInputStream(fileName);
org.apache.commons.io.IOUtils.copy(is, response.getOutputStream());
response.setContentType("image/png");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
response.flushBuffer();
is.close();
}
}
}
Other endpoints also works well on tomcat.
According to what I understand, tomcat is trying to search for that path ('/myWebapp/files/18.png') in disk, instead of forward the request to spring app.
I googled this error and figured out I need to add something in my web.xml but cant figure out what exactly.