Michael Isvy

Michael Isvy

Alumni
Blog posts by Michael Isvy

Migrating a Spring Web MVC application from JSP to AngularJS

Engineering | August 19, 2015 | ...

Note on authors

This post is a guest post by Han Lim and Tony Nguyen. Han and Tony have done a great presentation at our Singapore Spring User Group on Spring + Angular JS. This blog is based on their presentation.

Abstract

In this article, we try to describe our experiences moving from server-side rendering view technologies like JSP, Struts and Velocity to client-side rendering view technologies using AngularJS, a popular Javascript framework for modern browsers. We will talk about some of the things to look out for when you are making this change and potential pitfalls you may encounter. If…

Free Spring - Hadoop Conference in Singapore

News | August 22, 2013 | ...

We are glad to announce that we will host a FREE conference about Spring and Hadoop on Friday August 30th in downtown Singapore from 6 to 8 PM.

Spring best practices: from Spring Petclinic to Spring Data Hadoop

Michael Isvy joined SpringSource (the company behind Spring, now part of Pivotal) in 2008. He has, since then, taught Spring to more than 1000 students in 10 different countries. He has presented on Spring at numerous conferences and is an active technical blogger on the SpringSource blog. Michael holds the position of Education Manager for the Asia-Pacific region at SpringSource…

Spring Petclinic is on Github!

Engineering | March 21, 2013 | ...

We are pleased to announce that the Spring Petclinic sample application has been refactored.

The source code is now available on github. Here is a screenshot of the new application:

And here is an overview of the new architecture:

Spring, Spring, Spring

We have used the following Spring features:

  • Dependency Injection using Annotations
  • Data Access Integration using jdbc (JdbcTemplate), JPA or Spring Data JPA (repository layer). You can choose which implementation to use by setting up the corresponding bean profile in web.xml or in one of the JUnit tests.
  • Transactions using @Transactional (service layer)
  • Caching using @Cacheable with ehcache as a cache implementation (service layer)
  • Aspect Oriented Programming (to monitor how many times has been called each of the Repository methods)
  • Spring MVC: Form validation using Bean Validation (JSR-303)
  • Spring MVC: content negotiation (html, xml or atom) using ContentNegotiatingViewResolver.
  • Spring MVC: exception handling using SimpleMappingExceptionResolver
  • Spring MVC: use of the Spring MVC Test Framework

 

Our Vibrant Community

We have had quite a lot of contributions from experts in our community (including the leads of several open source projects).

 

Thymeleaf

In case you haven’t heard of it yet, Thymeleaf can be seen as a replacement for JSP. it defines itself as an  XML / XHTML / HTML5 template engine.

It is based on some plain HTML files with a little bit of namespace magic.

Daniel and Soraya from the Thymeleaf project have created a Spring-Petclinic branch that uses Thymeleaf instead of JSP. They have documented the migration steps in this blog entry: http://www.thymeleaf.org/petclinic.html

The Thymeleaf branch of Spring Petclinic is available here: https://github.com/thymeleaf/thymeleafexamples-petclinic

To learn more about Thymeleaf: http://www.thymeleaf.org

To follow Thymeleaf on twitter: https://twitter.com/thymeleaf

 

Dandelion

Dandelion provides a set of taglibs that you can use with JSP or Thymeleaf.

We have used it inside Spring-Petclinic to work with DataTables. It generates tables based on jQuery DataTables and Bootstrap.

You can do things like that:


<datatables:table data="${ownerList}" id="dataTable"  theme="bootstrap2" export="pdf">
 <datatables:column title="Name" property="name" sortable="true" />
 <datatables:column title="Address" property="address" sortable="true" />
</datatables:table>

The output html table then looks like this:

Dandelion is used inside the main branch of Spring Petclinic.

Thibault Duchateau from the Dandelion project has written a nice blog entry that describes the migration of the Spring Petclinic application

To learn more about Dandelion:  http://dandelion.github.com/

To follow them on twitter: https://twitter.com/dandelion_proj

 

Maven or Gradle?

By default, Spring Petclinic uses Maven as it is the most common choice for Java applications. While Spring Petclinic is fairly small in comparison to most real-life applications, its Maven pom.xml file is pretty verbose already.

Li Yanhui from Thoughtworks China has been nice enough to migrate Spring Petclinic to Gradle. That is a great way to compare Maven and Gradle side by side. The build.gradle configuration file is indeed much simpler to understand. It currently contains 143 lines (as opposed to 543 lines for the Maven POM).

You can browse the Gradle-based version of Spring Petclinic here: https://github.com/whimet/spring-petclinic Thanks to them we have been able to identify a few places inside Spring Petclinic that contained code duplication and lacked of automated testing.

 

Performance Testing: Let’s Scale!

Would it be possible to take Spring Petclinic as it is now and scale it up to 1000 requests per second on a single server instance? Julien Dubois from Ippon Technologies has written a great series of five blog entries on that topic.

It answers questions such as: - Should I rely on the session context? (part 2) - Which Apache Tomcat connector should I use? (part 2) - Which database connection pool should I use? (part 3) - Is JDBC faster than JPA or Spring Data JPA? ( part 4) - What are the pros of using OpenSessionInViewFilter? ( part 4)

 

References

Spring Petclinic on GitHub Spring Petclinic on Cloud Foundry Petclinic + Thymeleaf Petclinic + Gradle

 

Spring MVC: from JSP and Tiles to Thymeleaf

Engineering | October 30, 2012 | ...

When it comes to the view layer, Spring @MVC gives you a variety of choices. In this article, we will first discuss the way you have most likely used the view layer in the past few years: JSP. We will see the bad and better ways to work with them (plain JSP, JSP with custom tags, Apache Tiles).

We will then discuss a new project called Thymeleaf, which you can use as an alternate approach to JSP.

As usual, you can find all the code samples discussed in the corresponding application on github.

Plain JSP

Let us get started with the below code sample:

<html …> <body>
 <div style="padding-top: 50px;">
   <jsp:include page="../menu.jspx"/>
   <c…

Integrating Spring MVC with jQuery for validation rules

Engineering | August 29, 2012 | ...

I was thrilled to see in a recent survey from zeroturnaround that Spring MVC was voted the most popular web framework for Java.

This framework is very flexible and there are dozens of ways to use it. As with all flexible frameworks that have many options, it is important to discuss common practices.

The project I have created for this blog entry uses features common in many Spring MVC applications. You will find something like this:

In controllers you will find typical Spring MVC features for mapping requests, extracting request data through annotations, data binding, file upload…

On the…

Transactions, Caching and AOP: understanding proxy usage in Spring

Engineering | May 23, 2012 | ...

In the Spring framework, many technical features rely on proxy usage. We are going to go in depth on this topic using three examples: Transactions, Caching and Java Configuration.

All the code samples shown in this blog entry are available on my github account.

Transactions

First step: no transaction

The Service class below is not transactional yet. Let’s first look at it as is and then make it become transactional.

@Service
public class AccountServiceImpl  implements AccountService {
 //…

//Not specifying a transaction policy here!
 public void create(Account account) {
 entityManager.persist(account);
 }
}

Since the method “create” is not transactional, it will most likely throw an exception (because this Account object should not…