Element type "properties" must be declared

最近将老项目从JDK1.8 升级到 JDK11 其中用到了 text-context xml文件配置属性

example
<entry key="pp.rest.service.id">example</entry>
<entry key="pp.rest.service.username">example</entry>
<entry key="pp.rest.service.password">example</entry>
<entry key="pp.rest.service.url">example</entry>  

<entry key="adapter.isFollowRedirects">true</entry>
<entry key="adapter.readTimeout">30000</entry>
<entry key="adapter.connectionTimeout">30000</entry>

文件已经定义了 properties,但是依然报错:
Caused by: org.xml.sax.SAXParseException: Element type "properties" must be declared.

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 以下回答来自chatgpt:

    这个错误通常是因为不正确的 XML 声明导致的。

    1. 首先,确保你的 XML 文件中声明了正确的 DTD (Document Type Definition)。

    比如,如果你的 XML 文件使用 Spring Framework 的命名空间和属性,则需声明如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    
        <!-- your beans configuration here -->
    
    </beans>
    
    1. 如果第一步没有解决问题,那么可能是你的 XML 文件中对应 DTD 或 XSD 文件没有正确定义。这种情况下,你需要检查一下你的文件路径和 schemaLocation 是否正确,以及 DTD 或 XSD 文件是不是存在于指定的路径下。

    2. 如果以上两步仍然没有解决问题,那么你可能需要进一步排查这个问题了,比如检查一下你的 XML 文件是否存在语法错误,或者是其他配置文件是否与此冲突等。

    最后,如果以上三步都没有解决问题,那么很遗憾,我也无法再提供更多的帮助了。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^