Spring Integration

JPAstreamer comes with first-party support for projects built on top of Spring Boot. Dependency Injection is a fundamental feature of the Spring framework. With this in mind, a JPAstreamer autoconfiguration module can be used to quickly and easily integrate JPAstreamer into your Spring Boot projects.

Installing the autoconfiguration module

The installation process will differ depending on the build tool you’re using. In this guide, Maven and Gradle are covered.

Maven

For Maven projects, the following JPAstreamer dependency must be added to the project’s pom.xml file:

<dependencies>
    <dependency>
        <groupId>com.speedment.jpastreamer.integration.spring</groupId>
        <artifactId>spring-boot-jpastreamer-autoconfigure</artifactId>
        <version>${jpa-streamer-version}</version>
    </dependency>
</dependencies>

Gradle

For Gradle projects, the following JPAstreamer dependency must be added to the project’s build.gradle file:

repositories {
    mavenCentral()
}

dependencies {
    compile "com.speedment.jpastreamer.integration.spring:spring-boot-jpastreamer-autoconfigure:version"
}

Accessing JPAstreamer

Once the required dependencies are installed, you can access JPAStreamer using Spring’s Dependency Injection system:

@Service
public class DummyService {

    @Autowired
    private final JPAStreamer jpaStreamer;
}

Direct field injection is usually not recommended, it’s preferable to inject your dependencies via a constructor:

@Service
public class DummyService {

    private final JPAStreamer jpaStreamer;

    @Autowired
    public DummyService(final JPAStreamer jpaStreamer) {
        this.jpaStreamer = jpaStreamer;
    }
}
JPAstreamer’s autoconfiguration relies on a EntityManagerFactory bean being present. If you’re using Spring Data JPA, this is already handled for you.