Spring Petclinic已上线Github!

工程 | Michael Isvy | 2013年3月21日 | ...

我们很高兴地宣布,Spring Petclinic示例应用程序已重构。

源代码现已在github上可用。这是新应用程序的截图:

以下是新架构的概述

Spring, Spring, Spring

我们使用了以下Spring特性

  • 使用注解进行依赖注入
  • 使用jdbc (JdbcTemplate)、JPA或Spring Data JPA (repository层) 进行数据访问集成。您可以通过在web.xml或JUnit测试中设置相应的bean profile来选择要使用的实现。
  • 使用@Transactional进行事务处理(服务层)
  • 使用@Cacheable和ehcache作为缓存实现进行缓存(服务层)
  • 面向切面编程(监控每个Repository方法被调用的次数)
  • Spring MVC:使用Bean Validation (JSR-303) 进行表单验证
  • Spring MVC:使用ContentNegotiatingViewResolver进行内容协商(html、xml或atom)。
  • Spring MVC:使用SimpleMappingExceptionResolver进行异常处理
  • Spring MVC:使用Spring MVC测试框架

 

我们充满活力的社区

我们获得了社区中许多专家的贡献(包括几个开源项目的负责人)。

 

Thymeleaf

如果您还没有听说过,Thymeleaf可以被视为JSP的替代品。它将自己定义为XML / XHTML / HTML5模板引擎。

它基于一些普通的HTML文件,带有一些命名空间的魔法。

Thymeleaf项目的Daniel和Soraya创建了一个Spring-Petclinic分支,该分支使用Thymeleaf代替JSP。他们在这篇博客文章中记录了迁移步骤:http://www.thymeleaf.org/petclinic.html

Spring Petclinic的Thymeleaf分支可在此处获取:https://github.com/thymeleaf/thymeleafexamples-petclinic

了解更多关于Thymeleaf的信息:http://www.thymeleaf.org

在twitter上关注Thymeleaf:https://twitter.com/thymeleaf

 

Dandelion

Dandelion提供了一组标签库,您可以将其与JSP或Thymeleaf一起使用。

我们已在Spring-Petclinic内部使用它来处理DataTables。它基于jQuery DataTables和Bootstrap生成表格。

你可以这样做


<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>

输出的html表格看起来像这样

Dandelion在Spring Petclinic的主分支中使用。

Dandelion项目的Thibault Duchateau撰写了一篇精彩的博客文章,描述了Spring Petclinic应用程序的迁移

了解更多关于Dandelion的信息:http://dandelion.github.com/

在twitter上关注他们:https://twitter.com/dandelion_proj

 

Maven还是Gradle?

默认情况下,Spring Petclinic使用Maven,因为它是Java应用程序最常见的选择。虽然Spring Petclinic与大多数实际应用程序相比相当小,但其Maven pom.xml文件已经非常冗长。

来自Thoughtworks China的Li Yanhui非常友好地将Spring Petclinic迁移到Gradle。这是一种并排比较Maven和Gradle的好方法。build.gradle配置文件确实更易于理解。它目前包含143行(而Maven POM为543行)。

您可以在此处浏览基于Gradle的Spring Petclinic版本:https://github.com/whimet/spring-petclinic 感谢他们,我们能够识别出Spring Petclinic内部一些存在代码重复和缺乏自动化测试的地方。

 

性能测试:让我们扩展!

是否有可能在单个服务器实例上将当前的Spring Petclinic扩展到每秒1000个请求?Ippon Technologies的Julien Dubois就此主题撰写了一系列五篇精彩的博客文章。

它回答了以下问题: - 我应该依赖会话上下文吗?(第二部分) - 我应该使用哪个Apache Tomcat连接器?(第二部分) - 我应该使用哪个数据库连接池?(第三部分) - JDBC是否比JPA或Spring Data JPA更快?( 第四部分) - 使用OpenSessionInViewFilter有什么优点?( 第四部分)

 

参考文献

GitHub上的Spring Petclinic Cloud Foundry上的Spring Petclinic Petclinic + Thymeleaf Petclinic + Gradle

 

获取 Spring 新闻通讯

通过 Spring 新闻通讯保持联系

订阅