我已经成功创建并部署了一个 bundle(Servlet),它接受用户的用户名和密码,现在我想将它保存在/content/mydata/下的 JCR 存储库中 我遇到异常
java.lang.IllegalArgumentException: relPath is not a relative path: {} {}oliver
这是我的代码
public class CustomerJCRAccessImp implements CustomerService {
@Reference
protected SlingRepository repository;
protected static final Logger log = LoggerFactory.getLogger(CustomerJCRAccessImp.class);
public void insertData(String username, String password) throws Exception {
log.error("Username ::"+username+" Password ::"+password);
log.error("XXX:: Inside the Service Method");
Session session= repository.loginAdministrative(null);
Node node= session.getRootNode();
Node contentNode = node.getNode("content");
//node.i
Node myAppNode = contentNode.getNode("myApp");
log.error("THE VALUE OF myApp NODE ::"+myAppNode);
Node user = myAppNode.addNode("/"+username);
user.setProperty("Roll No", "1");
user.setProperty("Age", "10");
user.setPrimaryType("nt:unstructured");
session.save();
session.logout();
}
protected void bindRepository(SlingRepository repository) {
this.repository = repository;
}
}
我已经通过引用此链接完成了此操作 http://helpx.adobe.com/experience-manager/using/persisting-cq-data-java-content.html 提前致谢。
最佳答案
addNode() 的相对路径参数方法不应以“/”开头。 尝试
Node user = videojetNode.addNode(username);
虽然我同意文档中的术语“relPath”具有误导性,但 relPath 应该是您要在当前节点下创建的节点的名称,或者应该以子节点的名称,并包含要在其下创建节点的目标节点的相对路径。
例如。如果当前节点是 content 并且您有以下树
/
|_content
|_x
|_y
如果您希望添加一个名为 z 的节点作为 y 的子节点,则可以将 relPath 指定为
Node myNode = contentNode.addNode("x/y/z");
注意:如果任何中间节点不可用,将抛出 PathNotFoundException
关于java - 在 JCR 节点中保存数据,我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22828484/