我的 xml 仅适用于架构的版本 。当我尝试使用最新的(当前)时,我收到以下错误:1.8spring-mongo.xsd3.0
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mongo:mongo'. [11]
cvc-complex-type.3.2.2: Attribute 'mongo-ref' is not allowed to appear in element 'mongo:db-factory'. [12]
cvc-complex-type.3.2.2: Attribute 'username' is not allowed to appear in element 'mongo:db-factory'. [12]
cvc-complex-type.3.2.2: Attribute 'password' is not allowed to appear in element 'mongo:db-factory'. [12]
Run Code Online (Sandbox Code Playgroud)
这是我的 xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
<mongo:mongo id="mongo" replica-set="${mongo.replicaset}" write-concern="${mongo.write_concern:REPLICAS_SAFE}"/>
<mongo:db-factory id="DbFactory" mongo-ref="mongo" dbname="${mongo.db}" username="${mongo.username}" password="${mongo.password}"/>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="DbFactory"/>
<property name="writeResultChecking" value="EXCEPTION"/>
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
根据其他答案,我尝试将credentials属性与连接字符串一起使用,但即使这样也会被拒绝?
您应该将 xsd 版本修复为您的匹配spring-data-mongo版本。(为了防止意外,而不是“依赖最新的”)\n所以:
xsi:schemaLocation="...\n http://www.springframework.org/schema/data/mongo\n http://www.springframework.org/schema/data/mongo/spring-mongo.YOUR.VERSION.xsd">\nRun Code Online (Sandbox Code Playgroud)\n要将 xml 升级到 3.0(当前最新):\n请参阅此处
\n\n\n表 4. 删除的 XML 命名空间元素和属性:
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n
元素属性 3.x 中的替换 评论 <mongo:db-factory mongo-ref="\xe2\x80\xa6\xe2\x80\x8b" /><mongo:db-factory mongo-client-ref="\xe2\x80\xa6\xe2\x80\x8b" />引用 com.mongodb.client.MongoClient。 <mongo:mongo-client credentials="\xe2\x80\xa6\xe2\x80\x8b" /><mongo:mongo-client credential="\xe2\x80\xa6\xe2\x80\x8b" />单一认证数据而不是列表。 ... ... ...
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element \'mongo:mongo\'. [11] \nRun Code Online (Sandbox Code Playgroud)\n\ncvc-complex-type.3.2.2: Attribute \'mongo-ref\' is not allowed to appear in element \'mongo:db-factory\'. [12] \nRun Code Online (Sandbox Code Playgroud)\n因此,将其替换为mongo-client-ref(引用 1 中的客户端)。
cvc-complex-type.3.2.2: Attribute \'username\' is not allowed to appear in element \'mongo:db-factory\'. [12] \ncvc-complex-type.3.2.2: Attribute \'password\' is not allowed to appear in element \'mongo:db-factory\'. [12] \nRun Code Online (Sandbox Code Playgroud)\n您应该使用:credential的属性mongo-client。
请同时将表 3(writeConcern现在具有不同的值)视为表 5 ( mongo-client-ref, connection-string)。
对于connection-string,最好参考(当前)Mongo DB 手册。
这是应用此答案后编辑的 xml,不确定它是否正确,但我没有收到 xml 验证错误:
\n<?xml version="1.0" encoding="UTF-8"?>\n<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n xmlns="http://www.springframework.org/schema/beans"\n xmlns:mongo="http://www.springframework.org/schema/data/mongo"\n xsi:schemaLocation="\n http://www.springframework.org/schema/beans\n http://www.springframework.org/schema/beans/spring-beans.xsd\n http://www.springframework.org/schema/data/mongo\n http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">\n\n <mongo:mongo-client id="mongo" replica-set="${mongo.replicaset}" />\n <mongo:db-factory id="DbFactory" mongo-client-ref="mongo" dbname="${mongo.db}" connection-string="mongodb://${mongo.username}:${mongo.password}@${mongo.db}" write-concern="${mongo.write_concern:REPLICAS_SAFE}" />\n <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">\n <constructor-arg ref="DbFactory"/>\n <property name="writeResultChecking" value="EXCEPTION"/>\n </bean>\n</beans>\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
603 次 |
| 最近记录: |