本地配置MarkLogic Java API报错No user provided,求解决方法
问题背景
我已经安装了ML 9.0.3,按照文档在本地配置,并修改了config.properties文件:
# properties to configure the examples example.admin_password=x example.host=localhost example.port=9963 example.authentication_type=digest
运行控制台第一个程序com.marklogic.client.example.tutorial.Example_01_CreateJSON时,出现如下错误:
Exception in thread "main" java.lang.IllegalArgumentException: No user provided
at com.marklogic.client.impl.JerseyServices.connect(JerseyServices.java:186)
at com.marklogic.client.impl.JerseyServices.connect(JerseyServices.java:165)
at com.marklogic.client.DatabaseClientFactory.newClient(DatabaseClientFactory.java:156)
at com.marklogic.client.DatabaseClientFactory.newClient(DatabaseClientFactory.java:125)
at com.marklogic.client.example.tutorial.Example_01_CreateJSON.main(Example_01_CreateJSON.java:37)
解决方案
这个错误的原因非常直接——你的配置文件里缺少了连接MarkLogic所需的用户名配置项。示例程序在创建数据库客户端时,需要同时获取用户名和密码才能完成digest认证。
你只需要做以下两步:
- 打开
config.properties,添加用户名配置行:
(如果你不是用默认的admin用户,替换成你实际使用的有权限的用户名即可)example.admin_user=admin - 确认
example.admin_password=x中的x是该用户名对应的正确密码,并且这个用户拥有创建文档的权限(新安装的MarkLogic中admin用户默认具备所有权限)。
修改后的完整配置应该是这样:
# properties to configure the examples example.admin_user=admin example.admin_password=x example.host=localhost example.port=9963 example.authentication_type=digest
保存配置后重新运行程序,这个异常应该就会消失了。
内容的提问来源于stack exchange,提问作者Private

