Skip to content

Instantly share code, notes, and snippets.

@iyengarajay
Created August 9, 2016 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iyengarajay/01e91a206df2b1016b20d2f1290f3860 to your computer and use it in GitHub Desktop.
Save iyengarajay/01e91a206df2b1016b20d2f1290f3860 to your computer and use it in GitHub Desktop.
package com.example;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication implements CommandLineRunner {
// Use constructor injection.
@Autowired
private EmployeeRepository employeeRepository;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
// Initialization to add data to h2 db.
@Override
public void run(String... args) throws Exception {
List<Employee> employees = getAllEmployees();
employees.forEach(employee -> employeeRepository.save(employee));
}
private List<Employee> getAllEmployees() {
List<Employee> employees = new ArrayList<>();
employees.add(new Employee("Barney", "Stinson"));
employees.add(new Employee("Alex", "Hitch"));
employees.add(new Employee("Douglas", "Ramsey"));
return employees;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment