Getting Started with SpringBoot in Intellij IDEA Community Edition

We can use Intellij IDEA Community Edition for working with SpringBoot applications as we don’t need support for configuring servers like Tomcat, Wildlfy etc and can simply run the applications by running main() method.

However, there is no provision in Intellij IDEA Community Edition to create SpringBoot application directly, the way it supports in Ultimate Edition.

We can go to http://start.spring.io/ and generate the project and then import into our IDE. But it would be nice to be able to create the SpringBoot project from IDE itself.

One simple alternative I found to circumvent this problem is by using Project Template support in IntellijIDEA.

For the first time you can create the SpringBoot project from http://start.spring.io/ and import it into Intellij IDE.
If you wish you can add any other starters that you commonly use, configure properties like JDBC parameters etc.

Now click on menu Tools -> Save Project as Template. Enter Name and Description for the template.

SBTemplate

Once the template is created we can use that template while creating new projects.

Select File -> New -> Project.

NewProjDlg

In the New Project Dialog, you can see User-defined section and when you click on User-defined you can see all the project templates we created.
Select the SpringBootBasic template we created earlier and provide the project name and click Finish.

Well, we won’t get any fancy Spring support features like Ultimate Edition provides, but it will help us to get started quickly without requiring us to manually create Maven/Gradle project, configure <parent> etc etc.
Of course, it is not specific to SpringBoot only, we can create templates for any of our favorite tech stacks.

Happy coding 🙂

Update on SpringBoot : Learn By Example book

I would like to let you know that I have updated/added the following sections to my SpringBoot : Learn By Example book.

springboot_learn_by_example

Additions to existing chapters:

  • Working with Multiple Databases
  • Exposing JPA entities with bi-directional references through RESTful services

In some of our applications we need to work with multiple databases. For example, we may have a primary database and a reporting database where most the application uses primary database and the application reports will be generated out of reporting database data.

The section Working with Multiple Databases explains how to configure multiple databases while using JPA in a SpringBoot application.

As SpringBoot can’t auto-configure components such as TransactionManagers, EntityManagerFactoryBeans, DataSourceInitializers for multiple databases automatically, this section will show how to turn-off auto-configuration mechanism for a specific AutoConfiguration class and provide the required configuration explicitly.

Added new chapter : Chapter 16: Deploying SpringBoot Applications.

  • Running SpringBoot applications in production mode
  • Deploying SpringBoot application on Heroku
  • Running SpringBoot application on Docker

In this new chapter I have explained how to run the SpringBoot self-contained jar in production and how to override the configuration properties configured in src/main/resources/application-*.properties.

This chapter also covers how we can deploy SpringBoot + JPA + Postgres application on Heroku platform by linking to our GitHub repository. We can enable automatic deployment so that whenever we push our changes to our Github repository the updated application will be automatically deployed on Heroku.

Finally, we will learn how to run a SpringBoot + JPA + Postgres application on Docker container. This chapter explains how to run both Postgres server and application in separate containers and link them. Then, we will also look into running the docker containers using DockerCompose instead of starting them individually.

I hope you will enjoy these new additions. 🙂

How to fix “vt-x is disabled in the bios” error?

If you face the “vt-x is disabled in the bios” error while trying to run Android emulator, here is the solution that worked for me.

Step 1: Enable Virtualization Technology in BIOS

Go to BIOS Setup and enable “Virtualization Technology” option.

On my Lenovo laptop this option was already enabled, but still getting this error. I have disabled it and re-enabled it, then it is working.

Step 2: Install HAXM Installer from Android SDK Manager

Start the Android SDK Manager, select Extras -> Intel x86 Emulator Accelerator (HAXM Installer) and install it.

HAXM

Step 3: Install Intel’s HAXM

Install Intel’s HAXM by running the following installer.

%SDK_LOCATION%\extras\intel\Hardware_Accelerated_Execution_Manager\intelhaxm-android.exe

That’s it. Now restart the system and hopefully you should be able to run the Android Emulator.

My New Book SpringBoot : Learn By Example Published Today

I am happy to announce that my new book SpringBoot : Learn By Example  got published today on Leanpub.

 

springboot_learn_by_example

What is SpringBoot?

Spring is one of the most popular Java frameworks out there to build web and enterprise application.
Spring supports variety of configuration approaches (XML, Annotations, JavaConfig etc) and properly configuring Spring applications become a bit tedious and repetitive process. To avoid these problems Spring team introduced SpringBoot to address the complexity of configuring Spring application.

SpringBoot is an opinionated approach to configure Spring based applications. SpringBoot automatically configures the application components based on various criteria like the jars you have on classpath, beans you have already configured, properties configured etc which makes it very easy to get up and running quickly.

I strongly believe that the best way to learn or teach is by using examples. This book is filled with plenty of examples explaining the concepts  in step by step manner.

Who this book is for?

If you are looking for a fast paced guide to learn how to build Spring based applications using SpringBoot this book is for you!!.

If you are a Spring developer but haven’t get your hands on SpringBoot and you feel like I know the drill, just tell me how to do it in SpringBoot way..this books is what you are looking for!!!

If you are just starting to use SpringBoot and it is working great but it all looks magical and you want to understand how SpringBoot works behind the scenes..this book will definitely be helpful to you!!

If you are a seasoned Spring developer with good grasp of Spring framework concepts and you just want a fast-paced guide to learn SpringBoot quickly..sure..this book is definitely for you!!

I see lot of people asking “What is the difference between SpringMVC and SpringBoot?”, “Should I use SpringBoot or SpringMVC for my next web application?” etc etc. See Here, Here and Here . The short answer is SpringBoot is nothing but Spring only..but it helps you a lot to build Spring based applications quickly. The next question would be How?. The best way to explain it is by creating an application WITHOUT SpringBoot and show how quickly you can develop the same application WITH SpringBoot.

This book explains how normally we build Spring application without SpringBoot and shows how we can build the same application using SpringBoot in much easier way so that you can correlate the concepts and see how SpringBoot increases developer productivity.

SpringBoot does so many things behind the scenes to automatically configure the application. This book explains how SpringBoot AutoConfiguration works behind the scenes in very detailed manner and show how we can create our own AutoConfiguration as well.

What this book covers?

The SpringBoot : Learn By Example book covers the concepts that we commonly use in our Spring applications.

  • What is SpringBoot and how to get started with SpringBoot?
  • How SpringBoot AutoConfiguration Works behind the scenes using @Conditional?
  • SpringBoot goodies like Logging, ConfigurationProperties, DeveloperTools
  • Working with Databases using JdbcTemplate, MyBatis, JOOQ, Spring Data JPA
  • Working with MongoDB NoSQL database
  • Developing Web Applications using SpringMVC
    • SpringBoot Web Starter awesomeness
    • Using Thymeleaf Views
    • File Uploading
    • Validation, I18N
  • Developing RESTful Services using SpringMVC and Spring Data REST
  • Consuming SpringBoot REST API from AngularJS application
  • Securing Web applications and REST API
  • Monitoring SpringBoot applications with SpringBoot Actuator
  • Testing SpringBoot applications

To get complete list of topics covered in this book please see the below Table of Contents.



Table of Contents:

1. Introduction to SpringBoot

  • Overview of Spring framework
  • Developing Web Application using SpringMVC and JPA
  • A Quick Taste of SpringBoot

2. Getting Started with SpringBoot

  • What is SpringBoot?
  • Our First SpringBoot Application

3. SpringBoot Behind the scenes

  • Exploring the Power of @Conditional
  • How SpringBoot AutoConfiguration Works?

4. Creating Custom SpringBoot Starter

  • Create twitter4j-spring-boot-starter

5. SpringBoot Essentials

  • Logging
  • Externalizing Configuration Properties
  • Developer Tools

6. Working with JdbcTemplate

  • Using JdbcTemplate without SpringBoot
  • Using JdbcTemplate with SpringBoot
  • Initializing Database
  • How to use other Connection Pooling libraries?

7. Working with MyBatis

  • Using SpringBoot MyBatis Starter

8. Working with JOOQ

  • Using SpringBoot JOOQ Starter

9. Working with JPA

  • Introducing Spring Data JPA
  • Using Spring Data JPA with SpringBoot

10. Working with MongoDB

  • Introducing MongoDB
  • Getting Started with MongoDB using Mongo Shell
  • Talking to MongoDB using Spring Data Mongo

11. Web Applications with SpringBoot

  • Developing Web Application using SpringBoot
  • Using Tomcat, Jetty, Undertow Embedded Servlet Containers
  • Customizing SpringMVC configuration
  • SpringBoot web application as deployable war
  • SpringBoot Supporting View Templates
  • Working with Thymeleaf Forms
  • Data Validation
  • File Uploading
  • Using ResourceBundles for Internationalization (I18N)

12. Building REST API using SpringBoot

  • Introduction to RESTful WebServices
  • REST API using SpringMVC
  • REST API using Spring Data REST
  • Consuming REST API from AngularJS

13. Securing Web Applications using SpringBoot

  • Spring Security in SpringBoot Web Application
  • Method Level Security
  • Securing REST API using SpringSecurity

14. SpringBoot Actuator

  • Exploring Actuator Endpoints
  • Customizing Actuator Endpoints
  • Securing Actuator Endpoints
  • CORS support for Actuator Endpoints
  • Monitoring and management over JMX
  • Monitoring and management using a remote shell

15. Testing SpringBoot Applications

  • Testing Support in SpringBoot
  • Testing RESTful Services using RestTemplate
  • Testing Secured Controller/Service Methods
  • Testing with Mockito

Thank You Manuel Jordan

I would like to thank Manuel Jordan (@dr_pompeii) for reviewing the book and providing feedback which helped me a lot to improve the quality of the book content.

If  you wish please do me a favour by spreading the word on Twitter, Facebook, LinkedIn etc.
I hope you will enjoy the book 🙂

My Review of Sanjay Patel’s Spring Course

Spring is the most popular Java framework for building web and enterprise applications. There are plenty of official documentation, books, and Training Courses available for Spring framework on web.

I got an opportunity to review Sanjay Patel‘s Spring Course Material which is divided into 3 modules.

http://www.naturalprogrammer.com/spring-tutorial/

The total course is divided into 3 modules covering various aspects of web application development using Spring/SpringBoot framework.

  1. Module I : Spring Framework 4 And Dependency Injection For Beginners
  2. Module II : Spring Framework for the Real World
  3. Module III : Spring Framework REST API Development

Module I: Spring Framework 4 and Dependency Injection For Beginners

This module covers the basics of Spring Dependency Injection mechanism using Annotations and JavaConfig based approach using SpringBoot.

The material is structured in such a way that the readers can follow the course and practice in a step by step manner.

The following topics are covered in this Module:

  • Quick and brief introduction to Dependency Injection using Spring
  • Loading and binding properties from properties files
  • Using environment profiles
  • Brief introduction about using @Conditional
  • Sending Email

There are plenty of Spring core feature are there which can’t be covered in a single book or video.But I think it would be great to cover the most commonly used features Scopes, like LifeCycle methods @PostConstruct and @PreDestroy etc.

Overall, this module will be good for people who already have some basic knowledge on Spring. But for complete beginners it may be overwhelming to understand all these Spring concepts along with SpringBoot.

Module II: Spring Framework for the Real World

This module covers the most of the aspects of web application development. The explanation is straight forward and to the point.

This module explains the concepts by implementing various use-cases of typical User Management such as SignIn, SignUp, Forgot Password, Reset Password etc.

This module covers:

  • Implementing Controllers, Request Parameters binding
  • Performing Validations, Customizing Error Messages
  • Creating custom validation constraints
  • Exception Handling
  • Brief introduction to Spring Data JPA and Transaction Handling
  • Implementing Security using Spring Security
    • Configuring Spring Security
    • Form based Login, Remember Me, Password Encryption
    • Spring Security JSP Tag libraries
  • A quick introduction to Asynchronous processing using @Async
  • Scheduling tasks using @Scheduled

This module gives hands-on experience on using many of the Spring web application development tasks. This module also contains creating many commonly used utilities such as getting I18N messages, getting login user details etc which comes very handy.

We can also use JSP with SpringBoot jar type packaging as described in Spring Boot With JSPs in Executable Jars(https://dzone.com/articles/spring-boot-with-jsps-in-executable-jars-1)

Module III: Spring Framework REST API Development

This module covers building REST API using SpringBoot. This module contains excellent material covering most of the aspects required for building a good REST API.

This module covers:

  • Creating REST Endpoints using @RestController
  • Exception handling via @ControllerAdvice
  • Environment specific properties using Profiles
  • Using @ConfigurationProperties to bind properties
  • How to catch constraint violation exceptions
  • How to use reCAPTCHA
  • Securing REST API
    • Customizing Spring Security to support REST API
    • Switching User
    • Handling CSRF and CORS

This module filled with lot of interesting material required to build a Secured REST API.

However, I feel like there are few important things which are not covered:                        

  • No mention of Serializing JPA entities
  • Dealing with bi-directional JPA Entity relation serialization issues
  • Token based Security

Throughout the course author explain the concepts in clear and to the point manner. Also, the course is backed by an application SpringLemon which contains all the code used in this course.

Overall this course looks very to me and I strongly recommend this course if you are looking for a fast paced Spring course.