I have this configuration in src / main / resources for my small Spring application to load:
server.port = 8090 spring.datasource.driverClassName = org.h2.Driver spring.datasource.url = jdbc:h2:file:~/stapler
I know that this configuration is correctly selected, so there is a valid port number 8090 in the application launch log. There is also the initDb () @PostConstruct method, which creates and inserts data into 2 tables of this database:
package com.avk.stapler.init; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.jdbc.core.JdbcTemplate; import javax.annotation.PostConstruct; @SpringBootApplication public class DbInitializer { @Autowired private JdbcTemplate jdbcTemplate; public static void main(String[] args) { SpringApplication.run(DbInitializer.class, args); } @PostConstruct private void initDb() { System.out.println("Creating table employees"); jdbcTemplate.execute("drop table employees if exists"); jdbcTemplate.execute("create table employees(id serial, name varchar(255), surname varchar(255))"); jdbcTemplate.execute("insert into employees(name, surname) values('Jan', 'Kowalski')"); jdbcTemplate.execute("insert into employees(name, surname) values('Stefan', 'Nowak')"); System.out.println("Creating table allocations"); jdbcTemplate.execute("drop table allocations if exists"); jdbcTemplate.execute("create table allocations(id serial, week int, year int, shift int, employee_id bigint)"); jdbcTemplate.execute("insert into allocations(week, year, shift, employee_id) values(29, 2015, 1, 1)"); jdbcTemplate.execute("insert into allocations(week, year, shift, employee_id) values(28, 2015, 2, 1)"); jdbcTemplate.execute("insert into allocations(week, year, shift, employee_id) values(29, 2015, 3, 2)"); jdbcTemplate.execute("insert into allocations(week, year, shift, employee_id) values(28, 2015, 2, 2)"); } }
I see this logged in at startup, I don't think there are more logs in the database:
2015-09-30 22:41:22.948 INFO 2832 --- [ main] osjdeEmbeddedDatabaseFactory : Creating embedded database 'testdb' Creating table employees Creating table allocations
And as a result of the above, I would like to see the file "stapler.h2.db" in my home directory, which is not the case. What needs to be changed here for the DB file to appear?