Guest User

Untitled

a guest
Aug 30th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. SpringApplicationBuilder appBuilder = new SpringApplicationBuilder();
  2. appBuilder.headless(false);
  3. appBuilder.listeners(new ApplicationListener<ApplicationEvent>() {
  4. @Override
  5. public void onApplicationEvent(ApplicationEvent event) {
  6. if (event instanceof ApplicationEnvironmentPreparedEvent) {
  7. Environment env = ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
  8. String datasourceUrl = env.getProperty(RepositoryConfig.JDBC_URL_PROPERTY);
  9.  
  10. File db = FirebirdUtil.extractDatabaseFile(datasourceUrl);
  11. if (db != null) {
  12. String user = env.getProperty(RepositoryConfig.JDBC_USER_PROPERTY);
  13. String password = env.getProperty(RepositoryConfig.JDBC_PASSWORD_PROPERTY);
  14.  
  15. // this will create the FDB file if it doesn't exists
  16. FirebirdUtil.createDatabaseifNotExists(db, user, password);
  17. }
  18. }
  19. }
  20. });
  21.  
  22. @RunWith(SpringRunner.class)
  23. @SpringBootTest
  24. @ContextConfiguration(loader = CustomLoader.class)
  25. public class DemoApplicationTests {
  26.  
  27. public static class CustomLoader extends SpringBootContextLoader {
  28.  
  29. @Override
  30. protected SpringApplication getSpringApplication() {
  31. SpringApplication app = super.getSpringApplication();
  32. app.addListeners(new MyListener());
  33. return app;
  34. }
  35. }
Add Comment
Please, Sign In to add comment