JCR + Spring

pom.xml

Apache Jackrabbit Examples

Spring Configuration

You can create a Repository reference in Spring in multiple ways, but here’s one that uses the RepositoryImpl class:

    <bean id="repository">
        <constructor-arg index="0" ref="config" />
    </bean>
    <bean id="config" factory-method="create">
        <constructor-arg index="0" value="./repository.xml"/>
        <constructor-arg index="1" value="." />
    </bean>

This will create a repository in the current directory, using ./repository.xml as the configuration file. This isn’t as complete as se-jcr will be (hopefully) but this does work with Spring 3.0 and JackRabbit 2.0.

Integrating Java Content Repository and Spring

Posted by Costin Leau on Mar 12, 2007

JCR module

Part of Spring Modules, JCR module’s main objective is to simplify development with the JSR-170 API in a similar manner to that of the ORM package from the main Spring distribution. Features include:

  • JcrTemplate which allows execution of JcrCallback and exception handling (transforming checked JCR exceptions into unchecked Spring DAO exceptions). The template implements most of the methods from the JCR Session and can be easily used as a replacement. Moreover the template is aware of thread-bound sessions which can be used across several methods, functionality very useful when using a transactional repository.
  • RepositoryFactoryBean which configures, starts and stops the repository instances. As the JSR-170 doesn’t address the way the repository should be configured, implementations vary in this regard. The support contains predefined FactoryBeans for Jackrabbit and Jeceira and an abstract base class which can easily support other repositories.
  • SessionFactory which unifies the Repository,Credentials and Workspace interfaces and allows automatic registration of listeners and custom namespaces.
  • Spring declarative transactional support for repositories that implement the (optional) transactional feature.
  • OpenSessionInView interceptor and filter which allow the usage of the same session per thread across different components. Along with JcrTemplate, the retrieval, closure and management of the JCR session is externalized and totally transparent to the caller.

For this article, the reference implementation (Jackrabbit) will be used however, since the JCR module is using the javax.jcr interfaces changing the implementation is just a matter of configuration. Let’s see step by step how to use Java Content Repository on top of Jackrabbit and how Spring Modules can help.

Spring Extension JCR JSR standard support

The standard support works only with the JSR-170 API (represented by javax.jcr package) without making any use of specific features of the implementations (which we will discuss later).

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s