Onyx Database Spring Configuration

Onyx Database integrates easily with Spring. Configure the Persistence Manager and Persistence Manager Factory as Spring beans. In this example, we have used Spring Boot to bootstrap Onyx.

You can download the code for this example here:

OnyxDevTools/onyx-database-samples/spring-example.

  1. Add Spring dependencies within Maven

    In order to use Spring and Spring Boot, you must include the dependencies within your project.

  2. Define the Spring Configuration using annotations

    There is nothing special about the Spring configuration. If you have used Spring before, you will notice this is pretty standard.

    Notes:
    The class is annotations using @Configuration. This will work only if your Spring Application has the @EnableAutoConfiguration annotation.
    The PersistenceManagerFactory instance is Autowired. For this example, we are using a CachePersistenceManagerFactory. You can also choose from a EmbeddedPersistenceManagerFactory, RemotePersistenceManagerFactory or a custom persistence manager factory.
    The PersistenceManagerFactory is initialized within the Spring bean.
    There is also another Spring @Bean defined for the PersistenceManager
  3. Create a Spring Controller

    The MeetingController is configured by using a @Controller annotation. This class is used to be a data access object for persisting and fetching Meeting entities.

    Notes:
    The Persistence Manager is injected using the @Autowired annotation.
  4. Define a meeting entity

    The Meeting entity is a simple managed entity that reflects a scheduled event during someones work day.

  5. Create a Spring Boot Application

    The Spring Boot application is created by adding the @SpringBootApplication annotation. Within the main class, we are able to get the Spring application context and access the Spring Beans.

    Notes:
    The @EnableAutoConfiguration annotation is used to allow Spring to detect configuration classes automatically at runtime.
    The MeetingController is retrieved through the Spring Application Context. Notice the PersistenceManager is autowired within the MeetingController.
  6. Database Browser Overview