Skip to content

Instantly share code, notes, and snippets.

Created August 9, 2016 08:13
What would you like to do?
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;
public class DemoApplication implements CommandLineRunner {
// Use constructor injection.
private EmployeeRepository employeeRepository;
public static void main(String[] args) {, args);
// Initialization to add data to h2 db.
public void run(String... args) throws Exception {
List<Employee> employees = getAllEmployees();
employees.forEach(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