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).
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 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:```html
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 applicationTo 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)
ReferencesSpring Petclinic on GitHub Spring Petclinic on Cloud Foundry Petclinic + Thymeleaf Petclinic + Gradle