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>${groupid}</groupId>
  <artifactId>${artifactid}</artifactId>
  <version>${version_str}</version>
</dependency>
<dependency org="${groupid}" name="${artifactid}" rev="${version_str}"/>
@Grapes(
  @Grab(group='${groupid}', module='${artifactid}', version='${version_str}')
)
'${groupid}:${artifactid}:${version_str}'
'${groupid}:${artifactid}:${version_str}'
libraryDependencies += "${groupid}" % "${artifactid}" % "${version_str}"
[${groupid}/${artifactid} "${version_str}"]
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.

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 EbeanServer.
 */
public class MyEbeanServerFactory implements FactoryBean<EbeanServer> {

  public EbeanServer getObject() throws Exception {

    return createEbeanServer();
  }

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

  public boolean isSingleton() {
    return true;
  }

  /**
  * Create a EbeanServer instance.
  */
  private EbeanServer createEbeanServer() {

    ServerConfig config = new ServerConfig();
    config.setName("pg");

    // load configuration from ebean.properties
    config.loadFromProperties();
    config.setDefaultServer(true);
    ...
    // other programmatic configuration

    return EbeanServerFactory.create(config);
  }
}