Making full stack java development easier with JHipster

Making full stack java development easier with JHipster

If Java is the engine then Spring is the fuel. –Baeldung.

Well JHipster is the rocket.

I recently discovered this awesome project called JHipster,

It greatly simplifies Spring and Angular development while also boosting your productivity!

It makes it very easy to build a full stack Spring-boot and Angular application ready for production.

In this blog post I want to share it with you my experience on using JHipster for Angular and Spring developers.

I’ll discuss several things here, such as some of its core features, why JHipster is good for beginner developers and whether you should use JHipster at all.

 

What is JHipster?

If you don’t know, JHipster is a project generator, but it’s not just like any generator or CLI…

It significantly simplifies full stack Java development so much that it takes one command and a few questions before you’re full development stack is set up.

Their technology stack is the latest and greatest.

May it be that your requirements are a monolithic application or a micro service based architecture, JHipster has you covered.

The work flow is simple, and JHipster just generates the shell of your application for you. All the endless Spring configuration is done, Spring profiles are setup and deployment strategies are already thought out.

This significantly reduces the setup time and increases the developers productivity with nice entity creation, which I’ll talk about later.

It will do configuration for Thymeleaf, you databases, Spring profiles, etc.

You can basically think of JHipster as the setup you never had and the one you have always wanted.

What makes JHipster hip is that it adds some JavaScript from JavaScript world, more specifically TypeScript into you Spring project with Angular and uses the latest libraries and follows most of the programming trends.

 

JHipster features

Like I said, JHipster is a project generator for Java Spring and Angular based projects, but not only that it has an ocean of different useful awesome features.

Entities and CRUD

When generating a new project, you can choose between any of the popular databases that you want:

MySQL, MongoDB, Cassanda, MSSQL, etc

To find out more about its technology stack check out this link.

JHipster also speeds up developer productivity by implementing all the crud operations throughout the entire stack, so you won’t have to worry about it because it’s done for you.

That includes creating JPA entities, creating Spring Rest resources with basic CRUD functionality. On the client side, that’s too covered, you have Angular CRUD services ready to go.

JHipster has this new thing called the JHipster Domain Language (JDL) and JDL-Studio that allows you to write entities and entity relations in a visual editor.

For example a Person and Car entities, with relationships

Jdl-Studio snippet

You can then drop that down into JHipster and it’ll create all the JPA entities, DTOs, Spring Rest Controllers all the way through to the client side with Angular.

How fantastic is that?! It’s quick and easy!

By doing crud operations this way, you can focus on what’s important, writing all your business logic, which is what counts. Not having to sit and figure out all the configuration.

But what if I want to update my Entities and Models?

JHipster has a nice feature where you can update entities by adding/removing fields or relationships.

Everyone loves Microservices

A seemingly complex and fun buzz word that everyone is talking about.

Microservices are cool as they provide an architecture that can be infinitely scalable, quicker for development and no one will be attached to a large code base because of how small they are.

This architectural approach is simply building a complete application or a suite of related applications that share common resources by dividing them up and breaking them down into little services.

For example, if you have a User login and password reset, etc, and then also your business logic like a Todo application, you can split this two ways…

One service “User-Service” would handle the User accounts, profile, etc and the Todo service would handle storing tasks, creating tasks, etc.

Martin Fowler is the man who knows a lot more than I do and you should check out what he has to say about them. Microservices Guide, Microservices.

Anyways, JHipster has a very nice feature for generating a full fledge microservice architecture using Netflix’s open source software and the Spring Cloud project, also including Docker.

JHipster microservices
source from jhipster.github.io/microservices-architecture

They have already put in the work for creating an easy way to create new microservices that play with the rest quite easily.

Development

For a long time I couldn’t create a more complex application using Spring profiles, configuring the databases, using tests and so on because of how complex that kind of setup is and it’s requirements.

jHIpster obviously has this taken care of as its prime features.

You can choose between Gradle or Maven as your build manager, that configures tasks already, profiles integrated and configured for development or production databases

Docker

You have probably heard of Docker and used it at this point…

Jhipster loves Docker as it provides many Docker compose configurations already for you.

I remember setting up MongoDB a few months ago, and it refused to use any port I set in its configuration.

When I loaded MongoDB with Docker it just downloaded the Docker image and ran inside its own terminal virtual application and I could develop against it.

How cool it that?

What’s nice about Docker is that it puts everything in a container and you seamlessly run a Linux based application inside a container and it will work exactly how you want it on any other system.

Angular

Angular logo

I almost forgot to mention the hippest part of JHipster, Angular.

If you want to learn more about Angular, I did a blog post about Angular for Spring developers that you should check out.

Angular is tied into JHipster as is launched from the servlet container.

What’s nice about how they have configured Angular is that user authentication is already taken care for you. You can choose between or use multiple login strategies.

Specifically, Spring Security with HTTP sessions, underlying Spring Security is Spring’s Social Login with Facebook, Google …

JSON-Web-Tokens for stateless security or OAuth2 authentication.

JHipster has significantly improved the security model in terms of user experience and low-level Spring Security. You can read more about security here.

Many more…

I can’t write about all the other really nice features that JHipster has as I won’t have the time, but you can see how easy it is to create a fully fledged full stack application with Spring and Angular.

So I would encourage you to check out more features at JHipster.

Notably the contributions from big named companies like Google with their support with Kubernetes, Heroku, Storm path and so on.

 

Why I like JHipster

For a long time I couldn’t build a proper fullstack application that connected to an in-memory or production ready database.

I couldn’t setup Spring development profiles or could I have configured a successful login mechanism with Spring Security over a REST api.

Jhipster generates all this functionality and Java configuration straight out of the box.

So it’s good to go and read over those things and see how other people have implemented this stuff and you can most definitely learn from it.

I learned a lot in terms of to simplify development by just looking at how JHipster does things in a clean and elegant way.

At first I was a bit overwhelmed on day one looking at the generated code. And if you’re coming from a beginners standpoint it can feel overwhelming too…

But with reading over the code everyday and trying to piece things together you can  you’ll slowly grasp and see how things are implemented.

For example, I never saw the idea of using a Data-Transfer-Object in between an Entity and a ViewModel.

That functionality is of course optional.

Getting up to speed

JHipster uses most of the new technologies in terms of enterprise-grade web applications…

But it’s built-in such a way that developers can easily use them and more importantly, learn how to use them.

A lot of developers can use JHipster to learn how to use certain technologies from a highlevel and seeing them implemented rather than studying all the details of all of them and later on suffer trying to implement them.

For example, creating entities. JHipster provides a great explanation for how to create JPA entities and how you can to create them.

It also has a custom Domain Language for creating entities and mapping their relationships for use in JDL studio.

Creating your entity model using this approach from a high-level view and later seeing how they’re implemented will significantly allow new developers to learn about how JPA works and other technologies like Liquidbase that integrate with it.

So if you’re starting out or even a macho senior developer and specifically want to use Angular and Spring based applications, I would highly recommend that you use JHipster as you’ll learn by playing and also learn by using other very nice useful technologies.

Specifically, I want to specialize in enterprise web applications, and I too was unfamiliar to how other technologies work with each other.

Again, JHipster is not just Spring and Angular, it does provide other great technologies baked in with it, specifically messaging systems, like Apache Kafka.

I do find it weird that they wouldn’t have opted for RabbitMQ as it maintained by Pivotal.

 

What you may not like

Something you maybe concerned about is how much is does for you and maybe you don’t like the way it does something, therefore you would have to tear down and build up again over just building yourself.

Nothing is of-course free and the idea that suites your exact needs won’t be there by anybody other than yourself.

But the JHipster team had this in mind, that’s why they have gone through the efforts to provide a wide scenario of use cases.

Best practises

JHipster tries to use all the default configuration and styling as much as possible. (You can read that here at policies).

What JHipster is striving for is following the best practices that have come through years of practice and work.

Conceptually, I wouldn’t argue too much about they choices in terms of best practices.

You may prefer the way you have done something, and now someone else is going to change that…

But think about it, is your way of doing something going to be the best, in terms of best practice regards to scalability and more importantly ease of use for other developers?

The approach they have come up with is designed to follow best practices gathered from hundreds of other developers.

Otherwise… Why are you here? Why are you even using a framework? And not writing everything yourself from scratch?

I had this argument with a senior developer a while ago.

Keep in mind, the more high level code that you write, the more productivity you’ll have (in terms of getting more done).

That is what JHipster is ultimately striving for.

Style guides

For example you may not initially like the project structure, I thought it was weird too, but I realized how much it simplified the codebase.

You may look at how far they have split the Angular spec tests from the other Angular code, and the imports look weird (walking up the directory tree like 7 times).

Usually you would have your test suites altogether in Angular, but they have separated them into the test folder of main.

But again, it does make things easier to understand.

But at the end of the day it’s still the productivity you get, best practices and ease of use all baked into one thing, JHipster.

If you want to learn more about this argument, read JHipster policies.

Of course the JHipster homepage is here too.

 

Awesome resources

There is someone who is even a bigger fan of JHipster than I am and is an active core contributor, Matt Raible.

He has written a mini-book about JHipster, talks about it and it’s ease of use.

I encourage you to check him out if you want to learn a bit more about JHipster.

Adrian van den Houten

I'm Adrian van Houten, founder of ScholarCoder and a passionate software developer for full-stack web development. Read more about me here.