0

I have a spring application deployed on the cloud server, digital ocean.

i tried to generate the sitemap.xml file using https://www.xml-sitemaps.com/ but it only gives me one page. which can be access on https://hostname.com

i would like my sitemap to have something like

  1. https://hostname.com/page1
  2. https://hostname.com/page2

how can i make a sitemap for other pages which are bundle in a war file in a spring boot application.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Taj Masindi
  • 136
  • 4
  • 10

1 Answers1

0

If you are looking at exporting URLs mentioned in controllers, then you can get the URLs list from RequestMappingHandlerMapping.

@RestController
public class TestController {

    @Autowired
    private RequestMappingHandlerMapping re;

    @GetMapping("/sitemap.xml")
    public String getSitemap() {
        Map<RequestMappingInfo, HandlerMethod> handlerMethods = re.getHandlerMethods();
        List<String> urls = new ArrayList<>();
        for (Entry<RequestMappingInfo, HandlerMethod> entry : handlerMethods.entrySet()) {
            urls.addAll((entry.getKey().getPatternsCondition().getPatterns()));
        }
        // Construct XML response from urls and return it
    }

}
Ranjith
  • 1,623
  • 3
  • 21
  • 34
  • How can I get dynamic sitemap, I have API @RequestMapping(value="/sitemap / {state}") where state is dynamic. I am getting response- https://examplexyz.com/sitemap/{state} I want something like this, https://examplexyz.com/sitemap/California 2019-02-25T10:28:08+00:00 0.64 https://examplexyz.com/sitemap/Hawaii 2019-02-25T10:28:08+00:00 0.64 – Abhijeet Farakate Feb 25 '19 at 14:48