0

I am using spring boot 2 and typescript. I want my controller to serve static content and for which I followed every recommended spring boot way i.e.

  • I kept ui resources in /resources/static/dist/ because spring boot automatically picks it from there.

  • I am using @Controller annotation.

Now, when I do

@GetMapping(value = "/demo")
public String getMetadataPropertiesUI() {
    return "ui/dist/dummy.html";
} 

It is able to serve my html, which I want, means it is working perfectly fine till here. But, when I try to adding depth to @GetMapping i.e. changing @GetMapping(value = "/demo/dummy/") then it is not able to serve my content, I am getting 404 here.

I am unable to find any solution for this. Also I don't have any other endpoint in my application which can cause conflicts. I checked it here also but didn't find anything helpful.

Thanks

user3520629
  • 185
  • 1
  • 3
  • 15
  • I don't really understand what your question is about. If it's about loading static content, how are the controllers and the GetMapping annotations relevant? These would be used to serve *dynamic* content. What static content are you trying to load? Where is it located in your project, and which exact and complete URL do you use to try loading it? – JB Nizet Mar 14 '19 at 07:45
  • Hi @JBNizet, when I do a GET call on this /demo endpoint , it should serve me a .html file which is located in `/resources/static/ui/dist/dummy.html` . The issue is when I do a GET call on `/demo` it is working but when I changed it to `/demo/dummy` (i.e) adding more depth to my endpoint, I am getting 404. – user3520629 Mar 14 '19 at 08:08
  • 2
    Because you're using a relative path, instead of an absolute one. Add a `/` at the beginning: `return "/ui/dist/dummy.html"`. But really, what's the point of having controllers to forward to static resources? Why don't you put the static resources at the right place directly and serve them without going through a controller? – JB Nizet Mar 14 '19 at 08:11
  • Yes, It's kind of a requirement which I have to implement, and its working after adding a `/` in the beginning. Really thanks for your help. @JBNizet – user3520629 Mar 14 '19 at 08:54

0 Answers0