Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
SPRING COOKBOOK
SPRING COOKBOOK

SPRING COOKBOOK: Over 100 hands-on recipes to build Spring web applications easily and efficiently

Arrow left icon
Profile Icon Jerome Jaglale Profile Icon Yilmaz
Arrow right icon
$48.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (3 Ratings)
Paperback May 2015 234 pages 1st Edition
eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Jerome Jaglale Profile Icon Yilmaz
Arrow right icon
$48.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (3 Ratings)
Paperback May 2015 234 pages 1st Edition
eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

SPRING COOKBOOK

Chapter 1. Creating a Spring Application

In this chapter, we will cover the following recipes:

  • Installing Java, Maven, Tomcat, and Eclipse on Mac OS
  • Installing Java, Maven, Tomcat, and Eclipse on Ubuntu
  • Installing Java, Maven, Tomcat, and Eclipse on Windows
  • Creating a Spring web application
  • Running a Spring web application
  • Using Spring in a standard Java application

Introduction

In this chapter, we will first cover the installation of some of the tools for Spring development:

  • Java: Spring is a Java framework.
  • Maven: This is a build tool similar to Ant. It makes it easy to add Spring libraries to a project. Gradle is another option as a build tool.
  • Tomcat: This is a web server for Java web applications. You can also use JBoss, Jetty, GlassFish, or WebSphere.
  • Eclipse: This is an IDE. You can also use NetBeans, IntelliJ IDEA, and so on.

Then, we will build a Spring web application and run it with Tomcat.

Finally, we'll see how Spring can also be used in a standard Java application (not a web application).

Installing Java, Maven, Tomcat, and Eclipse on Mac OS

We will first install Java 8 because it's not installed by default on Mac OS 10.9 or higher version. Then, we will install Maven 3, a build tool similar to Ant, to manage the external Java libraries that we will use (Spring, Hibernate, and so on). Maven 3 also compiles source files and generates JAR and WAR files. We will also install Tomcat 8, a popular web server for Java web applications, which we will use throughout this book. JBoss, Jetty, GlassFish, or WebSphere could be used instead. Finally, we will install the Eclipse IDE, but you could also use NetBeans, IntelliJ IDEA, and so on.

How to do it…

Install Java first, then Maven, Tomcat, and Eclipse.

Installing Java

  1. Download Java from the Oracle website http://oracle.com. In the Java SE downloads section, choose the Java SE 8 SDK. Select Accept the License Agreement and download the Mac OS X x64 package. The direct link to the page is http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html.
    Installing Java
  2. Open the downloaded file, launch it, and complete the installation.
  3. In your ~/.bash_profile file, set the JAVA_HOME environment variable. Change jdk1.8.0_40.jdk to the actual folder name on your system (this depends on the version of Java you are using, which is updated regularly):
    export JAVA_HOME="/Library/Java/JavaVirtualMachines/ jdk1.8.0_40.jdk/Contents/Home"
  4. Open a new terminal and test whether it's working:
    $ java -version
    java version "1.8.0_40"
    Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
    Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
    

Installing Maven

  1. Download Maven from the Apache website http://maven.apache.org/download.cgi. Choose the Binary zip file of the current stable version:
    Installing Maven
  2. Uncompress the downloaded file and move the extracted folder to a convenient location (for example, ~/bin).
  3. In your ~/.bash_profile file, add a MAVEN HOME environment variable pointing to that folder. For example:
    export MAVEN_HOME=~/bin/apache-maven-3.3.1
  4. Add the bin subfolder to your PATH environment variable:
    export PATH=$PATH:$MAVEN_HOME/bin
  5. Open a new terminal and test whether it's working:
    $ mvn –v
    Apache Maven 3.3.1 (12a6b3...
    Maven home: /Users/jerome/bin/apache-maven-3.3.1
    Java version: 1.8.0_40, vendor: Oracle Corporation
    Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_...
    Default locale: en_US, platform encoding: UTF-8
    OS name: "mac os x", version: "10.9.5", arch... …
    

Installing Tomcat

  1. Download Tomcat from the Apache website http://tomcat.apache.org/download-80.cgi and choose the Core binary distribution.
    Installing Tomcat
  2. Uncompress the downloaded file and move the extracted folder to a convenient location (for example, ~/bin).
  3. Make the scripts in the bin subfolder executable:
    chmod +x bin/*.sh
  4. Launch Tomcat using the catalina.sh script:
    $ bin/catalina.sh run
    Using CATALINA_BASE:   /Users/jerome/bin/apache-tomcat-7.0.54
    ...
    INFO: Server startup in 852 ms
    
  5. Tomcat runs on the 8080 port by default. In a web browser, go to http://localhost:8080/ to check whether it's working.

Installing Eclipse

  1. Download Eclipse from http://www.eclipse.org/downloads/. Choose the Mac OS X 64 Bit version of Eclipse IDE for Java EE Developers.
    Installing Eclipse
  2. Uncompress the downloaded file and move the extracted folder to a convenient location (for example, ~/bin).
  3. Launch Eclipse by executing the eclipse binary:
    ./eclipse

There's more…

Tomcat can be run as a background process using these two scripts:

bin/startup.sh
bin/shutdown.sh

On a development machine, it's convenient to put Tomcat's folder somewhere in the home directory (for example, ~/bin) so that its contents can be updated without root privileges.

Installing Java, Maven, Tomcat, and Eclipse on Ubuntu

We will first install Java 8. Then, we will install Maven 3, a build tool similar to Ant, to manage the external Java libraries that we will use (Spring, Hibernate, so on). Maven 3 also compiles source files and generates JAR and WAR files. We will also install Tomcat 8, a popular web server for Java web applications, which we will use throughout this book. JBoss, Jetty, GlassFish, or WebSphere could be used instead. Finally, we will install the Eclipse IDE, but you could also use NetBeans, IntelliJ IDEA, and so on.

How to do it…

Install Java first, then Maven, Tomcat, and Eclipse.

Installing Java

  1. Add this PPA (Personal Package Archive):
    sudo add-apt-repository -y ppa:webupd8team/java
    
  2. Refresh the list of the available packages:
    sudo apt-get update
    
  3. Download and install Java 8:
    sudo apt-get install –y oracle-java8-installer
    
  4. Test whether it's working:
    $ java -version
    java version "1.8.0_40"
    Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
    Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25…
    

Installing Maven

  1. Download Maven from the Apache website http://maven.apache.org/download.cgi. Choose the Binary zip file of the current stable version:
    Installing Maven
  2. Uncompress the downloaded file and move the resulting folder to a convenient location (for example, ~/bin).
  3. In your ~/.bash_profile file, add a MAVEN HOME environment variable pointing to that folder. For example:
    export MAVEN_HOME=~/bin/apache-maven-3.3.1
  4. Add the bin subfolder to your PATH environment variable:
    export PATH=$PATH:$MAVEN_HOME/bin
  5. Open a new terminal and test whether it's working:
    $ mvn –v
    Apache Maven 3.3.1 (12a6b3...
    Maven home: /home/jerome/bin/apache-maven-3.3.1
    Java version: 1.8.0_40, vendor: Oracle Corporation
    
    

Installing Tomcat

  1. Download Tomcat from the Apache website http://tomcat.apache.org/download-80.cgi and choose the Core binary distribution.
    Installing Tomcat
  2. Uncompress the downloaded file and move the extracted folder to a convenient location (for example, ~/bin).
  3. Make the scripts in the bin subfolder executable:
    chmod +x bin/*.sh
  4. Launch Tomcat using the catalina.sh script:
    $ bin/catalina.sh run
    Using CATALINA_BASE:   /Users/jerome/bin/apache-tomcat-7.0.54
    ...
    INFO: Server startup in 852 ms
    
  5. Tomcat runs on the 8080 port by default. Go to http://localhost:8080/ to check whether it's working.

Installing Eclipse

  1. Download Eclipse from http://www.eclipse.org/downloads/. Choose the Linux 64 Bit version of Eclipse IDE for Java EE Developers.
    Installing Eclipse
  2. Uncompress the downloaded file and move the extracted folder to a convenient location (for example, ~/bin).
  3. Launch Eclipse by executing the eclipse binary:
    ./eclipse

There's more…

Tomcat can be run as a background process using these two scripts:

bin/startup.sh
bin/shutdown.sh

On a development machine, it's convenient to put Tomcat's folder somewhere in the home directory (for example, ~/bin) so that its contents can be updated without root privileges.

Installing Java, Maven, Tomcat, and Eclipse on Windows

We will first install Java 8. Then, we will install Maven 3, a build tool similar to Ant, to manage the external Java libraries that we will use (Spring, Hibernate, and so on). Maven 3 also compiles source files and generates JAR and WAR files. We will also install Tomcat 8, a popular web server for Java web applications, which we will use throughout this book. JBoss, Jetty, GlassFish, or WebSphere could be used instead. Finally, we will install the Eclipse IDE, but you could also use NetBeans, IntelliJ IDEA, and so on.

How to do it…

Install Java first, then Maven, Tomcat, and Eclipse.

Installing Java

  1. Download Java from the Oracle website http://oracle.com. In the Java SE downloads section, choose the Java SE 8 SDK. Select Accept the License Agreement and download the Windows x64 package. The direct link to the page is http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html.
    Installing Java
  2. Open the downloaded file, launch it, and complete the installation.
  3. Navigate to Control Panel | System and Security | System | Advanced system settings | Environment Variables….
  4. Add a JAVA_HOME system variable with the C:\Program Files\Java\jdk1.8.0_40 value. Change jdk1.8.0_40 to the actual folder name on your system (this depends on the version of Java, which is updated regularly).
    Installing Java
  5. Test whether it's working by opening Command Prompt and entering java –version.
    Installing Java

Installing Maven

  1. Download Maven from the Apache website http://maven.apache.org/download.cgi. Choose the Binary zip file of the current stable version:
    Installing Maven
  2. Uncompress the downloaded file.
  3. Create a Programs folder in your user folder.
  4. Move the extracted folder to it.
  5. Navigate to Control Panel | System and Security | System | Advanced system settings | Environment Variables….
  6. Add a MAVEN_HOME system variable with the path to the Maven folder. For example, C:\Users\jerome\Programs\apache-maven-3.2.1.
  7. Open the Path system variable.
  8. Append ;%MAVEN_HOME%\bin to it.
    Installing Maven
  9. Test whether it's working by opening a Command Prompt and entering mvn –v.
    Installing Maven

Installing Tomcat

  1. Download Tomcat from the Apache website http://tomcat.apache.org/download-80.cgi and choose the 32-bit/64-bit Windows Service Installer binary distribution.
    Installing Tomcat
  2. Launch and complete the installation.
  3. Tomcat runs on the 8080 port by default. Go to http://localhost:8080/ to check whether it's working.

Installing Eclipse

  1. Download Eclipse from http://www.eclipse.org/downloads/. Choose the Windows 64 Bit version of Eclipse IDE for Java EE Developers.
    Installing Eclipse
  2. Uncompress the downloaded file.
  3. Launch the eclipse program.

Creating a Spring web application

In this recipe, we will build a simple Spring web application with Eclipse. We will:

  • Create a new Maven project
  • Add Spring to it
  • Add two Java classes to configure Spring
  • Create a "Hello World" web page

In the next recipe, we will compile and run this web application.

How to do it…

In this section, we will create a Spring web application in Eclipse.

Creating a new Maven project in Eclipse

  1. In Eclipse, in the File menu, select New | Project….
  2. Under Maven, select Maven Project and click on Next >.
  3. Select the Create a simple project (skip archetype selection) checkbox and click on Next >.
  4. For the Group Id field, enter com.springcookbook. For the Artifact Id field, enter springwebapp. For Packaging, select war and click on Finish.

Adding Spring to the project using Maven

Open Maven's pom.xml configuration file at the root of the project. Select the pom.xml tab to edit the XML source code directly. Under the project XML node, define the versions for Java and Spring. Also add the Servlet API, Spring Core, and Spring MVC dependencies:

<properties>
  <java.version>1.8</java.version>
  <spring.version>4.1.5.RELEASE</spring.version>
</properties>

<dependencies>
  <!-- Servlet API -->
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
  </dependency>

  <!-- Spring Core -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
  </dependency>

  <!-- Spring MVC -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
  </dependency>
</dependencies>

Creating the configuration classes for Spring

  1. Create the Java packages com.springcookbook.config and com.springcookbook.controller; in the left-hand side pane Package Explorer, right-click on the project folder and select New | Package….
  2. In the com.springcookbook.config package, create the AppConfig class. In the Source menu, select Organize Imports to add the needed import declarations:
    package com.springcookbook.config;
    @Configuration
    @EnableWebMvc
    @ComponentScan (basePackages = {"com.springcookbook.controller"})
    public class AppConfig {  
    }
  3. Still in the com.springcookbook.config package, create the ServletInitializer class. Add the needed import declarations similarly:
    package com.springcookbook.config;
    
    public class ServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
        @Override
        protected Class<?>[] getRootConfigClasses() {
            return new Class<?>[0];
        }
        
        @Override
        protected Class<?>[] getServletConfigClasses() {
            return new Class<?>[]{AppConfig.class};
        }
    
        @Override
        protected String[] getServletMappings() {
            return new String[]{"/"};
        }
    }

Creating a "Hello World" web page

In the com.springcookbook.controller package, create the HelloController class and its hi() method:

@Controller
public class HelloController {
  @RequestMapping("hi")
  @ResponseBody
  public String hi() {
      return "Hello, world.";
  }
}

How it works…

This section will give more you details of what happened at every step.

Creating a new Maven project in Eclipse

The generated Maven project is a pom.xml configuration file along with a hierarchy of empty directories:

pom.xml
src
 |- main
    |- java
    |- resources
    |- webapp
 |- test
    |- java
    |- resources

Adding Spring to the project using Maven

The declared Maven libraries and their dependencies are automatically downloaded in the background by Eclipse. They are listed under Maven Dependencies in the left-hand side pane Package Explorer.

Tomcat provides the Servlet API dependency, but we still declared it because our code needs it to compile. Maven will not include it in the generated .war file because of the <scope>provided</scope> declaration.

Creating the configuration classes for Spring

AppConfig is a Spring configuration class. It is a standard Java class annotated with:

  • @Configuration: This declares it as a Spring configuration class
  • @EnableWebMvc: This enables Spring's ability to receive and process web requests
  • @ComponentScan(basePackages = {"com.springcookbook.controller"}): This scans the com.springcookbook.controller package for Spring components

ServletInitializer is a configuration class for Spring's servlet; it replaces the standard web.xml file. It will be detected automatically by SpringServletContainerInitializer, which is automatically called by any Servlet 3. ServletInitializer extends the AbstractAnnotationConfigDispatcherServletInitializer abstract class and implements the required methods:

  • getServletMappings(): This declares the servlet root URI.
  • getServletConfigClasses(): This declares the Spring configuration classes. Here, we declared the AppConfig class that was previously defined.

Creating a "Hello World" web page

We created a controller class in the com.springcookbook.controller package, which we declared in AppConfig. When navigating to http://localhost:8080/hi, the hi()method will be called and Hello, world. will be displayed in the browser. This will be explained further in Chapter 3, Using Controllers and Views.

Running a Spring web application

In this recipe, we will use the Spring web application from the previous recipe. We will compile it with Maven and run it with Tomcat.

How to do it…

Here are the steps to compile and run a Spring web application:

  1. In pom.xml, add this boilerplate code under the project XML node. It will allow Maven to generate .war files without requiring a web.xml file:
    <build>
        <finalName>springwebapp</finalName>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <version>2.5</version>
          <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
          </configuration>
        </plugin>
      </plugins>
    </build>
  2. In Eclipse, in the left-hand side pane Package Explorer, select the springwebapp project folder. In the Run menu, select Run and choose Maven install or you can execute mvn clean install in a terminal at the root of the project folder. In both cases, a target folder will be generated with the springwebapp.war file in it.
  3. Copy the target/springwebapp.war file to Tomcat's webapps folder.
  4. Launch Tomcat.
  5. In a web browser, go to http://localhost:8080/springwebapp/hi to check whether it's working.
    How to do it…

How it works…

In pom.xml the boilerplate code prevents Maven from throwing an error because there's no web.xml file. A web.xml file was required in Java web applications; however, since Servlet specification 3.0 (implemented in Tomcat 7 and higher versions), it's not required anymore.

There's more…

On Mac OS and Linux, you can create a symbolic link in Tomcat's webapps folder pointing to the .war file in your project folder. For example:

ln -s ~/eclipse_workspace/spring_webapp/target/springwebapp.war ~/bin/apache-tomcat/webapps/springwebapp.war

So, when the.war file is updated in your project folder, Tomcat will detect that it has been modified and will reload the application automatically.

Using Spring in a standard Java application

In this recipe, we will build a standard Java application (not a web application) using Spring. We will:

  • Create a new Maven project
  • Add Spring to it
  • Add a class to configure Spring
  • Add a User class
  • Define a User singleton in the Spring configuration class
  • Use the User singleton in the main() method

How to do it…

In this section, we will cover the steps to use Spring in a standard (not web) Java application.

Creating a new Maven project in Eclipse

  1. In Eclipse, in the File menu, select New | Project....
  2. Under Maven, select Maven Project and click on Next >.
  3. Select the Create a simple project (skip archetype selection) checkbox and click on Next >.
  4. For the Group Id field, enter com.springcookbook. For the Artifact Id field, enter springapp. Click on Finish.

Adding Spring to the project using Maven

Open Maven's pom.xml configuration file at the root of the project. Select the pom.xml tab to edit the XML source code directly. Under the project XML node, define the Java and Spring versions and add the Spring Core dependency:

<properties>
  <java.version>1.8</java.version>
  <spring.version>4.1.5.RELEASE</spring.version>
</properties>

<dependencies>
  <!-- Spring Core -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
  </dependency>
</dependencies>

Creating a configuration class for Spring

  1. Create the com.springcookbook.config Java package; in the left-hand side pane Package Explorer, right-click on the project and select New | Package….
  2. In the com.springcookbook.config package, create the AppConfig class. In the Source menu, select Organize Imports to add the needed import declarations:
    @Configuration
    public class AppConfig {
    }

Creating the User class

Create a User Java class with two String fields:

public class User {
  private String name;
  private String skill;
  
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  public String getSkill() {
    return skill;
  }
  public void setSkill(String skill) {
    this.skill = skill;
  }
}

Defining a User singleton in the Spring configuration class

In the AppConfig class, define a User bean:

  @Bean
  public User admin(){
    User u = new User();
    u.setName("Merlin");
    u.setSkill("Magic");
    return u;
  }

Using the User singleton in the main() method

  1. Create the com.springcookbook.main package with the Main class containing the main() method:
    package com.springcookbook.main;
    public class Main {
      public static void main(String[] args) {
    }
    }
  2. In the main() method, retrieve the User singleton and print its properties:
    AnnotationConfigApplicationContext springContext = new AnnotationConfigApplicationContext(AppConfig.class);
    
    User admin = (User) springContext.getBean("admin");
    
    System.out.println("admin name: " + admin.getName());
    System.out.println("admin skill: " + admin.getSkill());
    
    springContext.close();
  3. Test whether it's working; in the Run menu, select Run.
    Using the User singleton in the main() method

How it works...

We created a Java project to which we added Spring. We defined a User bean called admin (the bean name is by default the bean method name). Spring beans are explained in the next chapter.

In the Main class, we created a Spring context object from the AppConfig class and retrieved the admin bean from it. We used the bean and finally, closed the Spring context.

Left arrow icon Right arrow icon

Description

This book is for you if you have some experience with Java and web development (not necessarily in Java) and want to become proficient quickly with Spring.

Who is this book for?

This book is for you if you have some experience with Java and web development (not necessarily in Java) and want to become proficient quickly with Spring.

What you will learn

  • Install Maven and Tomcat and create a Spring MVC web application
  • Display, validate, and process forms
  • Query a database with minimal code
  • Authenticate users and manage their roles
  • Build REST, Java RMI, and Hessian web services
  • Create and schedule batch jobs
  • Offer customized page layouts to mobiles and tablets
  • Exchange data with Facebook and Twitter
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 25, 2015
Length: 234 pages
Edition : 1st
Language : English
ISBN-13 : 9781783985807
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : May 25, 2015
Length: 234 pages
Edition : 1st
Language : English
ISBN-13 : 9781783985807
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 130.97
SPRING COOKBOOK
$48.99
Spring Boot Cookbook
$34.99
Mastering Spring Application Development
$46.99
Total $ 130.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. Creating a Spring Application Chevron down icon Chevron up icon
2. Defining Beans and Using Dependency Injection Chevron down icon Chevron up icon
3. Using Controllers and Views Chevron down icon Chevron up icon
4. Querying a Database Chevron down icon Chevron up icon
5. Using Forms Chevron down icon Chevron up icon
6. Managing Security Chevron down icon Chevron up icon
7. Unit Testing Chevron down icon Chevron up icon
8. Running Batch Jobs Chevron down icon Chevron up icon
9. Handling Mobiles and Tablets Chevron down icon Chevron up icon
10. Connecting to Facebook and Twitter Chevron down icon Chevron up icon
11. Using the Java RMI, HTTP Invoker, Hessian, and REST Chevron down icon Chevron up icon
12. Using Aspect-oriented Programming Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(3 Ratings)
5 star 66.7%
4 star 0%
3 star 0%
2 star 33.3%
1 star 0%
Tapuz Jul 12, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book covers a wide range of base usecases and situations a developer has to face every day with Spring.Examples are clear and concise and very useful both to junior programmers to find how to do something and to senior to use as reference or to have bases to modify for living code.Very useful tool for having in one place numerous code examples and save time and doubts .
Amazon Verified review Amazon
George Victor Jul 03, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A nice book to learn the basics of spring framework. The recipes are concise and clear, and easy to follow. And covers a variety of topics such as spring security, mobile, social, AOP, UTs etc. Would have been even nicer if some really advanced recipes are also included, though I would give five stars for this book without a second thought for helping me in learning the basics of spring.
Amazon Verified review Amazon
han liu Jan 27, 2016
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
this book is not for new starter but some one with experience.(since it is named cookbook)there is no explanation of any concept and i found that most of time i have to do a lot of research in order to understand of the code.this cook book mostly use annotation.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela