My Problem:

I have an application built using the Jhipter generator, which is based on Spring Boot. The latest version of Jhipster allows you to include Elasticsearch as an option, so I have an application which runs an embedded instance of Elasticsearch in development mode and connects to a server instance in production mode.

When the application is running in development mode it connects perfectly fine to the embedded instance, but if I try to connect to an external instance I get the following error:

ERROR 5256 — [ main] .d.e.r.s.AbstractElasticsearchRepository : failed to load Elasticsearch nodes :
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []

I have an application which was using Spring boot version 1.3.6.RELEASE and in my server I was running an instance of Elasticsearch with version 2.3.1.

This error was due to two problems in my application:

– The client and the server version were different. I was using Spring Boot 1.3.6.RELEASE which includes Elasticsearch api version 1.5.2. while in my server I have an Elasticsearch version 2.3.1. so my client and server versions were not compatible. According to the documentation client and server major versions should be the same.
– Spring Boot makes use of ImmutableSettings class for auto configuration. This class has been removed from Elasticsearch 2.x.x and instead Settings.builder should be used.


Continue reading

My problem

Yesterday, I spent more than 5 hours trying to fix a compatibility issue between the latest version of spring-boot (1.2.6.RELEASE) and a mongoDb 3.0 database.

My problem was that I was using a free MongoDB-as-a-Service and they decided to upgrade from version 2.X to 3.0. As a result, my jhipster application could not connected to the database, and all that I could see in the logs were:

Caused by: com.mongodb.CommandFailureException: { “serverUsed” : “xxx” , “ok” : 0.0 , “errmsg” : “auth failed” , “code” : 18}

Continue reading

Recently, I have been working in a project which it was required to audit all the database transactions including the username. For this purpose I have been using Hibernate ORM Envers, which aims to enable easy auditing/versioning of persistent classes.

In order to show how to use Hibernate Envers in this post I have built a sample project, based on this Spring boot JPA project. Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. In this case it is very handy because it includes: an embedded tomcat,’starter’ POMs to simplify your Maven configuration, and REST web services ready to use.

This post is structure in 5 simple steps, neverthelesss, the last 2 steps are only useful if you would like to add the username (or any other information) to your revisions.

1. Configure Hibernate envers

2. Audit tables

3. Read Revisions

4. Add username information to each revision

5. Read Revision including username

Continue reading

In my last 2 projects, I have been using 2 different Yeoman generators: AngularJS and Jhipster. Both generators create a project with AngularJS and Grunt on the client side.

Setting up Intellij or Webstorm to debug AngularJS is not as straightforward as debugging other front-end frameworks like GWT. That’s why I am going to explain step by step how to set up Intellij to debug AngularJS.

1. Install the JetBrains IDE Support extension for Chrome

Go to the Chrome web store and add to chrome the JetBrains IDE Support.   intellijPlugin
Continue reading

A few weeks ago I started a new personal project using JHipster. JHipster is a great Yeoman generator used to generate a complete Spring application on the server side and AngularJS on the client side. Julien Dubois, the lead developer of this project, has done a excellent job putting a bunch of technologies all together (here you can find a complete list of all the technologies used).

In the Jhipster project, you can find a docker container which includes all the necessary libraries for running your project in development mode. Nevertheless, a docker container for production mode is missing.

What does this docker include?

The present docker is an extension of Dubois docker, including a MySql database, Grunt, Bower, and a bash script which creates a database and runs the application using the production profile.
Continue reading

During the last year, I have been involved in several projects developed with the Google Web Toolkit (GWT). Now, we are going to start a new project, and it’s time to evaluate the advantages and disadvantages of using GWT. In my opinion, these are the most relevant GWT pros and cons:

The advantages of GWT include:

  • If you are Java developer, the learning curve is very low, after all GWT was created to developed JavaScript front-end applications in Java.
  • Debugging any GWT application it is as easy as debugging any pure Java application. In my case,  I have been using the IntelliJ debugging facilities to debug both the client-side and the server-side Java code.
  • Developing GWT is quick thanks to error checking and syntax highlighting.
  • Easy to manage client history that means that GWT provides back button support.
  • You can use both JUnit and Mockito for unit testing. GWT makes very easy to apply TDD (Test-driven development) or BDD (Behavior-driven development) patterns.
  • GWT provides cross-browser support that means that your application will work similarly on the most recent versions of IE, Firefox, Chrome and Safari. Although we have found many incompatibilities with IE older versions.
  • The UI Binder framework is an excellent tool to build your apps as HTML pages with GWT widgets sprinkled throughout them.
  • Exchange Java object over HTTP between your client and server,  it is straightforward using the GWT RPC framework.
  • There are some good books about GWT. I would strongly recommend GWT in Action; it is very well explained and to the point.

Continue reading

In this post, I am going to talk about how to index JavaScript Object Notation (JSON) using Lucene Core. Apache Lucene is a high-performance, full-featured text search engine library written entirely in Java. Many companies like LinkedIn or Twitter use Lucene for Real-time search and faceted search. 

You can find all the code used in this post in github. In order to process a JSON file and index it, we need to:

  • Process a JSON file
  • Create an index
  • Add documents to the index
  • Commit the changes and close the index

Continue reading