Sitemap exposure starter for Spring apps.
- Implement
fun.wilddev.spring.sitemap.api.SiteMapLoader
:
@Component
public class ExampleSiteMapLoader implements SiteMapLoader {
@Override
public List<SiteMapEntry> load() {
return List.of(
new SiteMapEntry("https://test.website/test_1", LocalDateTime.now()),
new SiteMapEntry("https://test.website/test_2", LocalDateTime.now()),
new SiteMapEntry("https://test.website/test_3", LocalDateTime.now())
);
}
}
- Access the sitemap endpoint by
https://test.website/sitemap/xml
:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://test.website/test_1</loc>
<lastmod>2024-11-03T18:24:19Z</lastmod>
</url>
<url>
<loc>https://test.website/test_2</loc>
<lastmod>2024-11-03T17:11:16Z</lastmod>
</url>
<url>
<loc>https://test.website/test_3</loc>
<lastmod>2024-11-03T17:54:17Z</lastmod>
</url>
</urlset>
Build requirements:
- latest JDK and Maven
Also available in Maven central:
<dependency>
<groupId>fun.wilddev.lib</groupId>
<artifactId>spring-starter-sitemap</artifactId>
<version>1.0.1.RELEASE</version>
</dependency>