Build sitemap.xml by Java Spring [duplicate]

泄露秘密 提交于 2019-12-05 20:40:34

I hope you might have found your solution. Still, this answer may be helpful to someone.

Replacing @XmlRootElement(name = "urlset") with @XmlRootElement(name = "urlset", namespace = "http://www.sitemaps.org/schemas/sitemap/0.9") would solve your problem.

Update

If you have tried above solution. You will get the result something like following.

<ns2:urlset xmlns:ns2="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
    </url>
</ns2:urlset>

Solve this problem by adding package-info.java file in your package where you have placed XmlUrlSet class with the following content.

@XmlSchema(
    namespace="http://www.something.com/something", 
    elementFormDefault=XmlNsForm.QUALIFIED)
package your.package;

import javax.xml.bind.annotation.*;

It should solve your problem.

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
    </url>
</urlset>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!