spring framework petclinic

2025-12-07 0 461

Spring PetClinic Sample Application

Approved by the Spring team, this repo is a fork of the spring-projects/spring-petclinic.
It allows the Spring community to maintain a Petclinic version with a plain old Spring Framework configuration
and with a 3-layer architecture (i.e. presentation –> service –> repository).
The \”canonical\” implementation is now based on Spring Boot, Thymeleaf and aggregate-oriented domain.

Understanding the Spring Petclinic application with a few diagrams

See the presentation here (2017 update)

Running petclinic locally

With Maven command line

git clone https://*gith*ub.c*om/spring-petclinic/spring-framework-petclinic.git
cd spring-framework-petclinic
./mvnw jetty:run-war
# For Windows : ./mvnw.cmd jetty:run-war

With Docker

docker run -p 8080:8080 springcommunity/spring-framework-petclinic

You can then access petclinic here: http://*lo*c*alhost:8080/

In case you find a bug/suggested improvement for Spring Petclinic

Our issue tracker is available here: https://gi*thu*b.*com/spring-petclinic/spring-framework-petclinic/issues

Database configuration

In its default configuration, Petclinic uses an in-memory database (H2) which gets populated at startup with data.

A similar setups is provided for MySQL and PostgreSQL in case a persistent database configuration is needed.
To run petclinic locally using persistent database, it is needed to run with profile defined in main pom.xml file.

For MySQL database, it is needed to run with \’MySQL\’ profile defined in main pom.xml file.

./mvnw jetty:run-war -P MySQL

Before do this, would be good to check properties defined in MySQL profile inside pom.xml file.

<properties>
    <jpa.database>MYSQL</jpa.database>
    <jdbc.driverClassName>com.mysql.cj.jdbc.Driver</jdbc.driverClassName>
    <jdbc.url>jdbc:mysql://localhost:3306/petclinic?useUnicode=true</jdbc.url>
    <jdbc.username>petclinic</jdbc.username>
    <jdbc.password>petclinic</jdbc.password>
</properties>

You could start MySQL locally with whatever installer works for your OS, or with docker:

docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8

For PostgreSQL database, it is needed to run with \’PostgreSQL\’ profile defined in main pom.xml file.

./mvnw jetty:run-war -P PostgreSQL

Before do this, would be good to check properties defined in PostgreSQL profile inside pom.xml file.

<properties>
    <jpa.database>POSTGRESQL</jpa.database>
    <jdbc.driverClassName>org.postgresql.Driver</jdbc.driverClassName>
    <jdbc.url>jdbc:postgresql://localhost:5432/petclinic</jdbc.url>
    <jdbc.username>postgres</jdbc.username>
    <jdbc.password>petclinic</jdbc.password>
</properties>

You could also start PostgreSQL locally with whatever installer works for your OS, or with docker:

docker run --name postgres-petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 -d postgres:9.6.0

Persistence layer choice

The persistence layer have 3 available implementations: JPA (default), JDBC and Spring Data JPA.
The default JPA implementation could be changed by using a Spring profile: jdbc, spring-data-jpa and jpa.
As an example, you may use the -Dspring.profiles.active=jdbc VM options to start the application with the JDBC implementation.

./mvnw jetty:run-war -Dspring.profiles.active=jdbc

Compiling the CSS

There is a petclinic.css in src/main/webapp/resources/resources/css.
It was generated from the petclinic.scss source, combined with the Bootstrap library.
If you make changes to the scss, or upgrade Bootstrap, you will need to re-compile the CSS resources
using the Maven profile \”css\”, i.e. ./mvnw generate-resources -P css.

Working with Petclinic in your IDE

Prerequisites

The following items should be installed in your system:

  • Java 17 or newer (full JDK not a JRE)
  • Maven 3.5+ (https://maven.a*pa*c*he.org/install.html)
  • git command line tool (https://help.gi*th*u*b.com/articles/set-up-git)
  • Jetty 11.0+ or Tomcat 10+
  • Your prefered IDE
    • Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in Help -> About dialog. If m2e is not there, just follow the install process here: http://www.*ecli**pse.org/m2e/
    • Spring Tools Suite (STS)
    • IntelliJ IDEA

Steps:

  1. On the command line
git clone https://*gith*ub.c*om/spring-petclinic/spring-framework-petclinic.git
  1. Inside Eclipse or STS
File -> Import -> Maven -> Existing Maven project

Then either build on the command line ./mvnw generate-resources or using the Eclipse launcher (right click on project and Run As -> Maven install) to generate the CSS.
Configure a Jetty or a Tomcat web container then deploy the spring-petclinic.war file.

  1. Inside IntelliJ IDEA

In the main menu, select File > Open and select the Petclinic pom.xml. Click on the Open button.

CSS files are generated from the Maven build. You can either build them on the command line ./mvnw generate-resources
or right click on the spring-petclinic project then Maven -> Generates sources and Update Folders.

Go to the Run -> Edit Configuration then configure a Tomcat or a Jetty web container. Deploy the spring-petclinic.war file.
Run the application by clicking on the Run icon.

  1. Navigate to Petclinic

Visit http://**l*ocalhost:8080 in your browser.

Working with Petclinic in IntelliJ IDEA

prerequisites

The following items should be installed in your system:

Looking for something in particular?

Java Config
Java config branch Petclinic uses XML configuration by default. In case you\’d like to use Java Config instead, there is a Java Config branch available here
Inside the \’Web\’ layer Files
Spring MVC – XML integration mvc-view-config.xml
Spring MVC – ContentNegotiatingViewResolver mvc-view-config.xml
JSP custom tags WEB-INF/tags, createOrUpdateOwnerForm.jsp
JavaScript dependencies JavaScript libraries are declared as webjars in the pom.xml
Static resources config Resource mapping in Spring configuration
Static resources usage htmlHeader.tag, footer.tag
Thymeleaf In the late 2016, the original Spring Petclinic has moved from JSP to Thymeleaf.
\’Service\’ and \’Repository\’ layers Files
Transactions business-config.xml, ClinicServiceImpl.java
Cache tools-config.xml, ClinicServiceImpl.java
Bean Profiles business-config.xml, ClinicServiceJdbcTests.java, PetclinicInitializer.java
JDBC business-config.xml, jdbc folder
JPA business-config.xml, jpa folder
Spring Data JPA business-config.xml, springdatajpa folder

Publishing a Docker image

This application uses Google Jib to build an optimized Docker image
into the Docker Hub
repository.
The pom.xml has been configured to publish the image with a the springcommunity/spring-framework-petclinic image name.

Jib containerizes this WAR project by using the distroless Jetty as a base image.

Build and push the container image of Petclinic to the Docker Hub registry:

mvn jib:build

Interesting Spring Petclinic forks

The Spring Petclinic master branch in the main spring-projects
GitHub org is the \”canonical\” implementation, currently based on Spring Boot and Thymeleaf.

This spring-framework-petclinic project is one of the several forks
hosted in a special GitHub org: spring-petclinic.
If you have a special interest in a different technology stack
that could be used to implement the Pet Clinic then please join the community there.

Interaction with other open source projects

One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found some bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they\’ve been fixed/implemented in just a few days.
Here is a list of them:

Name Issue
Spring JDBC: simplify usage of NamedParameterJdbcTemplate SPR-10256 and SPR-10257
Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility HV-790 and HV-792
Spring Data: provide more flexibility when working with JPQL queries DATAJPA-292
Dandelion: improves the DandelionFilter for Jetty support 113

Contributing

The issue tracker is the preferred channel for bug reports, features requests and submitting pull requests.

For pull requests, editor preferences are available in the editor config for easy use in common text editors. Read more and download plugins at http://editorconfig.o***rg.

下载源码

通过命令行克隆项目:

git clone https://github.com/spring-petclinic/spring-framework-petclinic.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 开发教程 spring framework petclinic https://www.zuozi.net/31533.html

Fantasy
下一篇: Fantasy
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务