@Component
public class AddNode {
@Reference
static ResourceResolverFactory resolverFactory;
static Session session;
public static void main(String[] args) throws Exception {
ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);
Node root = session.getRootNode();
Node adobe = root.addNode("ProgramNode");
Node day = adobe.addNode("subnode");
day.setProperty("jcr:title", "programNode");
Node node = root.getNode("ProgramNode/subnode");
System.out.println(node.getPath());
System.out.println(node.getProperty("jcr:title").getString());
session.save();
session.logout();
}
}
这里 resolverFactory.getServiceResourceResolver(null); 我需要在 null 处传递任何参数。请举一些例子来访问存储库。