当前位置: 首页 > 软件库 > 数据库相关 > >

spring-framework-petclinic

授权协议 Apache-2.0 License
开发语言 C/C++
所属分类 数据库相关
软件类型 开源软件
地区 不详
投 递 者 祁飞飙
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

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 configurationand 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://github.com/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://localhost:8080/

petclinic-screenshot

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

Our issue tracker is available here: https://github.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

Working with Petclinic in your IDE

Prerequisites

The following items should be installed in your system:

Steps:

  1. On the command line
git clone https://github.com/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-resourcesor 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://localhost: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 imageinto the Docker Hubrepository.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-projectsGitHub org is the "canonical" implementation, currently based on Spring Boot and Thymeleaf.

This spring-framework-petclinic project is one of the several forkshosted in a special GitHub org: spring-petclinic.If you have a special interest in a different technology stackthat 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.org.

  • 创建Spring一个简单的Java项目       Spring框架,也就是开源框架,一般都应用于企业的应用程序的研发,Spring的用途比较广泛,在服务器端开发到任何Java应用都可以找到Spring的身影。我们应该怎么样搭建Spring环境呢? 需要的工具: 1、开发工具:My eclipse 2、Spring框架相关jar包 第一步:         首先在JAVA项目下创建一个lib文件夹

  • 我们刚刚发布了一个新教程和示例代码,以阐述如何在Windows Azure中使用 Java 相关技术。在该指南中,我们提供了分步教程,说明如何将 Java Spring Framework 应用程序(PetClinic 示例应用程序)迁移到 Windows Azure 云。此文档附带的代码同样也发布在 GitHub 中。我们鼓励 Java 开发人员下载并探索此新示例和教程。 详细信息 Window

  • 根据petclinic项目手把手教你剖析SpringFramework源代码---mvc篇 根据petclinic项目手把手教你剖析SpringFramework源代码---mvc篇 关键词:SpringFramework,mvc 二.SpringFramework的mvc 既然petclinic是个web application,我们当然从web.xml文件入手了。首先当然welcome-fil

  • spring-petclinic-master运行mvn install报错:Failed to execute goal io.spring.javaformat:spring-javaformat-maven-plugin:0.0.19:validate (default) on project spring-petclinic: Formatting violations found in

  • Spring Test官方部分文档翻译        这一章主要讲解了Spring框架对集成测试的支持以及单元测试的最优练习。Spring团队倡导测试驱动开发模式(TDD),在实际使用中发现,正确的使用IOC能让单元模块和功能集成的测试变得更加简单。 1.Sping test框架简介        测试是企业软件项目开发中必不可少的一部分。这一小节只要关注IOC容器整合单元测试的原理以及sprin

  • 第 7 章 事务管理 7.1. Spring事务抽象 Spring提供了一致的事务管理抽象。这个抽象是Spring最重要的抽象之一, 它有如下的优点: 为不同的事务API提供一致的编程模型,如JTA、JDBC、Hibernate、iBATIS数据库层 和JDO 提供比大多数事务API更简单的,易于使用的编程式事务管理API 整合Spring数据访问抽象 支持Spring声明式事务管理 传统上,J2

 相关资料
  • 本页涵盖了将 Shiro 集成到基于 Spring 的应用程序的方法。 Shiro 的 JavaBean 兼容性使得它非常适合通过 Spring XML 或其他基于 Spring 的配置机制。 Shiro 应用程序需要一个具有单例SecurityManager 实例的应用程序。请注意,这不会是一个静态的单例,但应该只有一个应用程序能够使用的实例,无论它是否是静态单例的。 单独的应用 这里是在 Sp

  • Delphi Spring Framework 是一个国际化的开源项目,主要为 Delphi 开发者提供一个类似 Spring 的基础框架,用以构建可靠、灵活和可扩展的企业应用程序。 系统架构:

  • 嗨,这个问题让我很困惑,我花了两天的时间在网上搜索,发现了许多类似的问题,但不幸的是,这些问题已经解决了,对我来说不起作用。所以这是我第一次问问题,因为我没有其他地方可以求助。我的背景我是自学成才的Java初学者,开始学习Spring框架这是我在线程“main”Java中的错误异常。ie.cit.cloud上的lang.NullPointerException。jdbctemplate。道。Ins

  • 我正在使用Spring与Spring靴。最近在尝试EhCache时,我尝试为EhCache启用日志记录。在Application.Properties中设置日志级别:

  • Spring Framework的一个关键组件是Aspect oriented programming (AOP)框架。 面向方面编程需要将程序逻辑分解为称为所谓关注点的不同部分。 跨越应用程序多个点的功能称为cross-cutting concerns ,这些跨领域问题在概念上与应用程序的业务逻辑分开。 有许多常见的好例子,如日志记录,审计,声明式事务,安全性,缓存等。 OOP中模块化的关键单元

  • 2. Spring Framework介绍 Spring Framework是一个为开发Java应用程序提供全方位基础架构支持的Java平台。基础架构由Spring负责,所以您可以专注于您的程序。 Spring使您可以从“普通Java对象”(POJO)开始构建应用程序,并将企业服务非侵入式地应用到POJO中。这种能力适用于Java SE编程模型和全部或部分的Java EE。 下面是一些作为程序开发