Java – connect to AEM 6.0 JCR: precondition failed

I encountered some problems connecting to the JCR repository in AEM 6.0 When I reach the point about creating a session on the replica, I get a javax jcr. lock. LockException:Precondition Failed.

I've been using this tutorial to start

This is my very simple code example:

import java.io.FileNotFoundException;
import java.io.FileReader;

import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.apache.jackrabbit.commons.JcrUtils;

import com.opencsv.CSVReader;


public class Main { 

    public static void main(String[] args) throws FileNotFoundException {
        Repository repository;
        FileReader fileReader;
        CSVReader csvReader;

        try {
            System.out.println("connecting to repository");
            repository = JcrUtils.getRepository("http://localhost:4502/crx/server");

            Session session = repository.login( new SimpleCredentials("admin","admin".tocharArray())); // throws javax.jcr.lock.LockException: Precondition Failed

        }
        catch(Exception e) {
            System.out.println(e);
        }
    }

}

Any guidance would be appreciated

Solution

Within the JCR repository, content is organized into one or more workspaces, each containing a hierarchical structure of nodes and attributes So to create a JCR session & you must pass the access nodes and properties of the workspace using credentials. The default AEM workspace is CRX default

Substitute:

Session session = repository.login( new SimpleCredentials("admin","admin".tocharArray()));

use:

Session session = repository.login( new SimpleCredentials("admin","admin".tocharArray()),"crx.default");

Please check the following links

javax. jcr. lock. LockException:Precondition Failed

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>