What is the right way for creating test data upon server startup and inserting them into the database (I\'m using a JPA/JDBC backed Postgres instance).
Preferably in
You can do like this
@SpringBootApplication
public class H2Application {
public static void main(String[] args) {
SpringApplication.run(H2Application.class, args);
}
@Bean
CommandLineRunner init (StudentRepo studentRepo){
return args -> {
List names = Arrays.asList("udara", "sampath");
names.forEach(name -> studentRepo.save(new Student(name)));
};
}
}