Book Image

Spring MVC Cookbook

By : Alexandre Bretet, Alex Bretet
Book Image

Spring MVC Cookbook

By: Alexandre Bretet, Alex Bretet

Overview of this book

Spring MVC is a lightweight application framework that comes with a great configuration by default. Being part of the Spring Framework, it naturally extended and supported it with an amazing set of recognizable annotations. External libraries can be plugged in and plugged out. It also possesses a request flow. Complete support of REST web services makes the Spring architecture an extremely consistent choice to support your front-end needs and Internet transformations. From the design of your Maven modules, you will achieve an Enterprise-standard for a stateless REST application based on Spring and Spring MVC with this book. This guide is unique in its style as it features a massive overview of practical development techniques brought together from the Spring ecosystem, the new JEE standards, the JavaScript revolution and Internet of Things. You will begin with the very first steps of Spring MVC's product design. Focused on deployment, viability, and maintainability, you will learn the use of Eclipse, Maven, and Git. You will walk through the separation of concerns driven by the microservices principles. Using Bootstrap and AngularJS, you will develop a responsive front-end, capable of interacting autonomously with a REST API. Later in the book, you will setup the Java Persistence API (JPA) within Spring; learn how to configure your Entities to reflect your domain needs, and discover Spring Data repositories. You will analyze how Spring MVC responds to complex HTTP requests. You will implement Hypermedia and HATEOAS to guide your customer's stateless conversation with the product and see how a messaging-service based on WebSocket can be configured. Finally you will learn how to set up and organize different levels of automated-tests, including logging and monitoring.
Table of Contents (16 chapters)
Spring MVC Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Installing Eclipse for JEE Developers and Java SE 8


The following recipe is about downloading and installing the Eclipse IDE for JEE developers and downloading and installing JDK 8 Oracle Hotspot.

Getting ready

This first recipe could appear redundant or unnecessary in regard to your education or experience. However, having a uniform configuration all along this book will provide you with many benefits.

For instance, you will certainly avoid unidentified bugs (integration or development). You will also experience the same interfaces as seen in the presented screenshots. Also, because the third-party products are living, you will not have the surprise of encountering unexpected screens or windows.

How to do it...

The whole first chapter in general requires a step by step cooperation. From the next chapter, we will be using GIT and your active involvement will be lightened.

  1. Download a distribution of the Eclipse IDE for Java EE developers:

    The product to download is not a compiled installer but a zip archive.

    • If you feel confident enough to use another version (more recent) of the Eclipse IDE for Java EE Developers, all of them can be found at https://www.eclipse.org/downloads.

      Tip

      For upcoming installations, on Windows, a few target locations are suggested to be in the root directory (C:\). To avoid permission-related issues, it would be better if your Windows user is configured to be a Local Administrator. If you can't be part of this group, feel free to target installation directories you have write access to.

  2. Extract the downloaded archive into an eclipse directory from the steps:

    • C:\Users\{system.username}\eclipse: Extract it here if you are on Windows

    • /home/usr/{system.username}/eclipse: Extract it here if you are on Linux

    • /Users/{system.username}/eclipse: Extract it here if you are on Mac OS X

  3. Select and download JDK 8:

    Note

    To avoid a compatibility issue later on, do stay consistent with the architecture choice (32 or 64 bits) that you have made earlier for the Eclipse archive.

  4. Install JDK 8 on the operating system of your choice using the following instructions:

    On Windows, this is a monitored installation initiated with an executable file:

    1. Execute the downloaded file and wait until you reach the next installation step

    2. On the installation-step window, pay attention to the destination directory and change it to C:\java\jdk1.8.X_XX (X_XX refers to the latest current version here. We will be using jdk1.8.0_25 in this book. Also, it won't be necessary to install an external JRE, so uncheck the public JRE feature.)

    On Linux/Mac, perform the following steps:

    1. Download the tar.gz archive corresponding to your environment

    2. Change the current directory to where you want to install Java. For easier instructions, let's agree on the /usr/java directory

    3. Move the downloaded tar.gz archive to this current directory

    4. Unpack the archive with the following command line targeting the name of your archive: tar zxvf jdk-8u25-linux-i586.tar.gz (this example is for a binary archive corresponding to a Linux x86 machine)

You must end up with the /usr/java/jdk1.8.0_25 directory structure that contains the /bin, /db, /jre, /include subdirectories.

How it works…

In this section we are going to provide more insights about the version of Eclipse we used and about how we chose this specific version of JVM.

Eclipse for Java EE developers

We have successfully installed the Eclipse IDE for Java EE developers here. Comparatively to Eclipse IDE for Java Developers, there are some additional packages coming along such as Java EE Developer Tools, Data Tools Platform, and JavaScript Development Tools. This version is appreciated for its ability to manage development servers as part of the IDE itself, its capability to customize project facets, and its ability to support JPA. The Luna version is officially Java SE 8 compatible; this has been a decisive factor at the time of writing.

Choosing a JVM

The choice of the JVM implementation could be discussed over performance, memory management, garbage collection, and optimization capabilities.

There are lots of different JVM implementations, including couple of open source solutions such as OpenJDK and IcedTea (RedHat). The choice of JVM really depends on the application's requirements. We have chosen Oracle Hotspot from experience and from reference implementations deployed in production; this JVM implementation can be trusted for a wide range of generic purposes. Hotspot also behaves very well if you have to run Java UI applications. Eclipse is one of them.

Java SE 8

If you haven't already played with Scala or Clojure, it is time that you took the functional programming train with Java! With Java SE 8, Lambda expressions reduce the amount of code dramatically providing improved readability and maintainability. We won't implement this Java 8 feature, but since it is probably the most popular, it must be highlighted as it has given a massive credit to the paradigm change. It is important, nowadays, to be familiar with these patterns.