FactoryBean

Rather than use the implementation provided in ebean-spring you can write your own Spring FactoryBean like the code below (or the spring boot EbeanFactoryBean example Factory Bean (programmatic configuration of EbeanServer)).

/**
* Simple Spring bean factory for creating the Database.
*/
public class MyDatabaseFactory implements FactoryBean<Database> {

  public Database getObject() throws Exception {

    return createDatabase();
  }

  public Class<?> getObjectType() {
    return Database.class;
  }

  public boolean isSingleton() {
    return true;
  }

  /**
  * Create a Database instance.
  */
  private Database createDatabase() {

    DatabaseConfig config = new DatabaseConfig();
    // plus any programmatic configuration
    return DatabaseFactory.create(config);
  }
}

Spring boot

Ebean is now aware of Spring boot runnable jar structure (for scanning the classpath). There is an example application showing:

This example does not show integration with Spring transactions (and instead uses Ebean's own transactions). Please review the ebean-spring project for that.

ebean-spring

The ebean-spring provides a FactoryBean as well as integration with Spring transactions.

<dependency>
  <groupId>io.ebean</groupId>
  <artifactId>ebean-spring</artifactId>
  <version>${version}</version>
</dependency>
<dependency org="io.ebean" name="ebean-spring" rev="${version}"/>
@Grapes(
  @Grab(group='io.ebean', module='ebean-spring', version='${version}')
)
'io.ebean:ebean-spring:${version}'
'io.ebean:ebean-spring:${version}'
libraryDependencies += "io.ebean" % "ebean-spring" % "${version}"
[io.ebean/ebean-spring "${version}"]
EbeanServerFactoryBean

EbeanServerFactoryBean is a spring FactoryBean that also holds a serverConfig. It is expected to be used in conjunction with default-ebean-server.xml which specifically registers SpringAwareJdbcTransactionManager as the external transaction manager on the ServerConfig.

SpringAwareJdbcTransactionManager

SpringAwareJdbcTransactionManager implements Ebean's ExternalTransactionManager API and provides the integration into Spring transaction management.

SpringJdbcTransaction

SpringJdbcTransaction extends Ebean's ExternalJdbcTransaction and is used by SpringAwareJdbcTransactionManager.

Edit Page