title: where microservices code in https://dzone.com/articles/spring-boot-creating project ?
body: <p>These days I'm hearing a lot about <strong>microservices</strong> and wondering to create <code>POC (Proof of Concept)</code> in order to be get applied in my project which will begin from scratched. I read a lots of blog about the mocroservices and found this link : <a href="https://dzone.com/articles/spring-boot-creating" rel="nofollow">https://dzone.com/articles/spring-boot-creating</a>. I was able to successfully run the code mentioned in the link. But I feels that its a Simple <code>Spring Boot REST example</code>, I am not sure what is the role of <code>microservices</code> in this example ? I'd like to understand this from technical point of view now as I theoretically understand what it is. Please guide. </p>
  
  <p>Please see code below for reference:</p>
  
  <pre><code>curl -vvv "http://localhost:8080/order?idCustomer=2&amp;idProduct=3&amp;amount=4"
  
  Trying 127.0.0.1...
  Connected to localhost (127.0.0.1) port 8080 (#0) 
  &gt; GET /order?idCustomer=2&amp;idProduct=3&amp;amount=4 HTTP/1.1 
  &gt; Host: localhost:8080 &gt; User-Agent: curl/7.46.0 
  &gt; Accept: / &gt; &lt; HTTP/1.1 200 &lt; Content-Type: application/json &lt; Content-Length: 173 
  &lt; Date: Fri, 09 Sep 2016 07:22:02 GMT 
  &lt; {"id":1,"amount":4,"orderDate":1473405722862,"customer":{"id":2,"name":"Customer 2","email":"Customer2@gmail.com"},"product":{"id":3,"sku":"abcd3","description":"Product3"}}* Connection #0 to host localhost left intact
  </code></pre>
  
  <p><strong>Application.java</strong></p>
  
  <pre><code>@SpringBootApplication
  public class Application {
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p><strong>ApplicationConfig.java</strong></p>
  
  <pre><code>@Configuration
  public class ApplicationConfig {
      @Named
      static class JerseyConfig extends ResourceConfig {
          public JerseyConfig() {
              this.packages("br.com.alexandreesl.handson.rest");
          }
      }
      @Bean
      public RestTemplate restTemplate() {
          RestTemplate restTemplate = new RestTemplate();
          return restTemplate;
      }
  }
  </code></pre>
  
  <p><strong>Customer.java</strong></p>
  
  <pre><code>public class Customer {
      private long id;
      private String name;
      private String email;
      // setters and getters
  }
  </code></pre>
  
  <p><strong>CustomerRest.java</strong></p>
  
  <pre><code>@Named
  @Path("/customer")
  public class CustomerRest {
      private static List&lt;Customer&gt; customers = new ArrayList&lt;Customer&gt;();
  
      static {
          Customer customer1 = new Customer();
          customer1.setId(1);
          customer1.setName("Customer 1");
          customer1.setEmail("customer1@gmail.com");
  
          Customer customer2 = new Customer();
          customer2.setId(2);
          customer2.setName("Customer 2");
          customer2.setEmail("Customer2@gmail.com");
  
          Customer customer3 = new Customer();
          customer3.setId(3);
          customer3.setName("Customer 3");
          customer3.setEmail("Customer3@gmail.com");
  
          Customer customer4 = new Customer();
          customer4.setId(4);
          customer4.setName("Customer 4");
          customer4.setEmail("Customer4@gmail.com");
  
          Customer customer5 = new Customer();
          customer5.setId(5);
          customer5.setName("Customer 5");
          customer5.setEmail("Customer5@gmail.com");
  
          customers.add(customer1);
          customers.add(customer2);
          customers.add(customer3);
          customers.add(customer4);
          customers.add(customer5);
      }
  
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public List&lt;Customer&gt; getCustomers() {
          return customers;
      }
  
      @GET
      @Path("/getCustomer")
      @Produces(MediaType.APPLICATION_JSON)
      public Customer getCustomer(@QueryParam("id") long id) {
          Customer cli = null;
          for (Customer c : customers) {
              if (c.getId() == id)
                  cli = c;
          }
          return cli;
      }
  }
  </code></pre>
  
  <p><strong>Order.java</strong></p>
  
  <pre><code>public class Order {
      private long id;
      private long amount;
      private Date orderDate;
      private Customer customer;
      private Product product;
        // setters and getters
  }
  </code></pre>
  
  <p><strong>OrderRest.java</strong></p>
  
  <pre><code>@Named
  @Path("/")
  public class OrderRest {
      private long id = 1;
  
      @Inject
      private RestTemplate restTemplate;
  
      @GET
      @Path("order")
      @Produces(MediaType.APPLICATION_JSON)
      public Order submitOrder(@QueryParam("idCustomer") long idCustomer,
              @QueryParam("idProduct") long idProduct,
              @QueryParam("amount") long amount) {
  
          Customer customer = restTemplate.getForObject("http://localhost:8080/customer/getCustomer?id={id}", Customer.class, idCustomer);
          Product product = restTemplate.getForObject("http://localhost:8080/product/getProduct?id={id}", Product.class,idProduct);
  
          Order order = new Order();
          order.setCustomer(customer);
          order.setProduct(product);
          order.setId(id);
          order.setAmount(amount);
          order.setOrderDate(new Date());
          id++;
          return order;
      }
  }
  </code></pre>
  
  <p><strong>Product.java</strong></p>
  
  <pre><code>public class Product {
      private long id;
      private String sku;
      private String description;
          // setters and getters
  }
  </code></pre>
  
  <p><strong>ProductRest.java</strong></p>
  
  <pre><code>@Named
  @Path("/product")
  public class ProductRest {
      private static List&lt;Product&gt; products = new ArrayList&lt;Product&gt;();
  
      static {
          Product product1 = new Product();
          product1.setId(1);
          product1.setSku("abcd1");
          product1.setDescription("Product1");
          Product product2 = new Product();
          product2.setId(2);
          product2.setSku("abcd2");
          product2.setDescription("Product2");
          Product product3 = new Product();
          product3.setId(3);
          product3.setSku("abcd3");
          product3.setDescription("Product3");
          Product product4 = new Product();
          product4.setId(4);
          product4.setSku("abcd4");
          product4.setDescription("Product4");
          products.add(product1);
          products.add(product2);
          products.add(product3);
          products.add(product4);
      }
  
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public List&lt;Product&gt; getProducts() {
          return products;
      }
  
      @GET
      @Path("/getProduct")
      @Produces(MediaType.APPLICATION_JSON)
      public Product getProduct(@QueryParam("id") long id) {
          Product prod = null;
          for (Product p : products) {
              if (p.getId() == id)
                  prod = p;
          }
          return prod;
      }
  }
  </code></pre>