我們很高興地宣佈,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