Some tips for JHipster

by Olivier Barais     jhipster  

Posted 2015.01.28 — Rennes, France

I really like JHipster project. The server stack is clean and ready for production

  • Spring Boot for easy application configuration
  • Maven or Gradle configuration for building, testing and running the application
  • “development” and “production” profiles (both for Maven and Gradle)
  • Spring Security
  • Spring MVC REST + Jackson
  • Optional WebSocket support with Spring Websocket
  • Spring Data JPA + Bean Validation
  • Database updates with Liquibase
  • MongoDB support if you’d rather use NoSQL instead of a classical relational database

Ready to go into production:

  • Monitoring with Metrics
  • Caching with ehcache (local cache) or hazelcast (distributed cache)
  • Optional HTTP session clustering with hazelcast
  • Optimized static resources (gzip filter, HTTP cache headers)
  • Log management with Logback, configurable at runtime
  • Connection pooling with HikariCP for optimum performance
  • Builds a standard WAR file or an executable JAR file

and the client part is also clean

Single Web page application:

  • Responsive Web Design
  • HTML5 Boilerplate
  • Twitter Bootstrap
  • AngularJS
  • Full internationalization support with Angular Translate
  • Optional WebSocket support with Spring Websocket

With the great Yeoman development workflow:

  • Easy installation of new JavaScript libraries with Bower
  • Build, optimization and live reload with Grunt or Gulp.js
  • Testing with Karma and PhantomJS

For me, it mainly misses some entity code geenrator that use TypeScript.

#Tips for JHipster.

##Define your own servlet

If you want to add your own servlet. It is quite easy. In the WebConfigurer class and in the method onStartup you can easily add declare new servlets.

servletContext.addServlet("foo"/*servlet name*/, MyServlet1.class /*servlet class*/);
servletContext.getServletRegistration("foo" /*servlet name*/).addMapping("/im/toto.png" /*servlet path*/);

Now you can add your servlet. In this example, it a servlet that plays with images to get only a part of a big image.


import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet1 extends HttpServlet  {

  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
      ServletContext cntx= getServletContext();
        // Get the absolute path of the image
        String filename =  cntx.getRealPath("/assets/images/hipster.png");
        // retrieve mimeType dynamically
        String mime = cntx.getMimeType(filename);
        if (mime == null) {
        File file = new File(filename);
        FileInputStream in = new FileInputStream(file);
        OutputStream out = resp.getOutputStream();
        BufferedImage bigImg =;
        BufferedImage small = bigImg.getSubimage(0, 0,200, 200);

        // Copy the contents of the file to the output stream
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ImageIO.write( small, "png", baos );
         byte[] imageInByte = baos.toByteArray();

##get the User which is currently logged in.


##Use Hibernate to create the schema. Sometimes, the use of liquidbase is a bit overkill especially at the beginning of a project if you just miss some attributes of your entities. In that case, you can let hibernate manage the database schema.

generate-ddl: true
     ddl-auto: update

It does not really follow the JHipster philosophy but it is usefull when you create a new app from scratch.