com.chevrier.legiondao.boot.Boot.java Source code

Java tutorial

Introduction

Here is the source code for com.chevrier.legiondao.boot.Boot.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.chevrier.legiondao.boot;

import com.chevrier.legiondao.config.AppConfig;
import com.chevrier.legiondao.config.ConfigJpa;
import com.chevrier.legiondao.entities.Personnage;
import com.chevrier.legiondao.repository.PersonnageRepository;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;

//@SpringBootApplication
public class Boot {

    private static final Logger log = LoggerFactory.getLogger(Boot.class);

    public static void main(String[] args) {
        //SpringApplication.run(Boot.class);

        SpringApplication app = new SpringApplication(ConfigJpa.class);
        //app.setLogStartupInfo(false);
        // on la lance
        ConfigurableApplicationContext context = app.run(args);

        PersonnageRepository personnageRepository = context.getBean(PersonnageRepository.class);

        Iterable<Personnage> allPersonnage = personnageRepository.findAll();

        allPersonnage.forEach(perso -> log.info(perso.getNom()));
        System.out.println("Let's inspect the beans provided by Spring Boot:");

        String[] beanNames = context.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        for (String beanName : beanNames) {
            System.out.println(beanName);
        }
        // fermeture du contexte Spring
        context.close();
    }

}