ua.epam.rd.pizzadelivery.SpringPizzaApp.java Source code

Java tutorial

Introduction

Here is the source code for ua.epam.rd.pizzadelivery.SpringPizzaApp.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 ua.epam.rd.pizzadelivery;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ua.epam.rd.pizzadelivery.domain.Customer;
import ua.epam.rd.pizzadelivery.domain.Order;
import ua.epam.rd.pizzadelivery.repository.PizzaRepository;
import ua.epam.rd.pizzadelivery.service.OrderService;

public class SpringPizzaApp {

    public static void main(String[] args) {
        ConfigurableApplicationContext appContext = new ClassPathXmlApplicationContext("appContext.xml");

        PizzaRepository pizzaRepository = (PizzaRepository) appContext.getBean("pizzaRepository");
        System.out.println(pizzaRepository);

        String[] beans = appContext.getBeanDefinitionNames();
        for (String b : beans) {
            System.out.println(b);
        }

        Customer customer = new Customer(1, "Andrii");
        OrderService orderService = (OrderService) appContext.getBean("orderService");

        Order order = orderService.placeNewOrder(customer, 1);

        System.out.println(order);

        appContext.close();
    }
}