Programmatically configure Ebean

You can programmatically build EbeanServer instances. ServerConfig is used to collect configuration settings and then passed to EbeanServerFactory to create the actual instance.

Note: When you use the Ebean singleton with a ebean.properties file it internally will create a ServerConfig, populate it from settings in the ebean.properties file and call EbeanServerFactory much like the code below.


// programmatically build a EbeanServer instance
// specify the configuration...

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

// Define DataSource parameters
DataSourceConfig postgresDb = new DataSourceConfig();
postgresDb.setDriver("org.postgresql.Driver");
postgresDb.setUsername("test");
postgresDb.setPassword("test");
postgresDb.setUrl("jdbc:postgresql://127.0.0.1:5432/test");
postgresDb.setHeartbeatSql("select count(*) from t_one");

config.setDataSourceConfig(postgresDb);

// specify a JNDI DataSource 
// config.setDataSourceJndiName("someJndiDataSourceName");

// set DDL options...
config.setDdlGenerate(true);
config.setDdlRun(true);

config.setDefaultServer(false);
config.setRegister(false);


// automatically determine the DatabasePlatform
// using the jdbc driver 
// config.setDatabasePlatform(new PostgresPlatform());

// specify the entity classes (and listeners etc)
// ... if these are not specified Ebean will search
// ... the classpath looking for entity classes.
config.addClass(Order.class);
config.addClass(Customer.class);
...

// specify jars to search for entity beans
config.addJar("someJarThatContainsEntityBeans.jar");

// create the EbeanServer instance
EbeanServer server = EbeanServerFactory.create(config);


Introduction User Guide (pdf) Install/Configure Public JavaDoc Whitepapers
General Database Specific Byte Code Deployment Annotations Features
Top Bugs Top Enhancements
woResponse