Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SpringApplicationBuilder appBuilder = new SpringApplicationBuilder();
- appBuilder.headless(false);
- appBuilder.listeners(new ApplicationListener<ApplicationEvent>() {
- @Override
- public void onApplicationEvent(ApplicationEvent event) {
- if (event instanceof ApplicationEnvironmentPreparedEvent) {
- Environment env = ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
- String datasourceUrl = env.getProperty(RepositoryConfig.JDBC_URL_PROPERTY);
- File db = FirebirdUtil.extractDatabaseFile(datasourceUrl);
- if (db != null) {
- String user = env.getProperty(RepositoryConfig.JDBC_USER_PROPERTY);
- String password = env.getProperty(RepositoryConfig.JDBC_PASSWORD_PROPERTY);
- // this will create the FDB file if it doesn't exists
- FirebirdUtil.createDatabaseifNotExists(db, user, password);
- }
- }
- }
- });
- @RunWith(SpringRunner.class)
- @SpringBootTest
- @ContextConfiguration(loader = CustomLoader.class)
- public class DemoApplicationTests {
- public static class CustomLoader extends SpringBootContextLoader {
- @Override
- protected SpringApplication getSpringApplication() {
- SpringApplication app = super.getSpringApplication();
- app.addListeners(new MyListener());
- return app;
- }
- }
Add Comment
Please, Sign In to add comment