Coder Social home page Coder Social logo

spring-petclinic / spring-framework-petclinic Goto Github PK

View Code? Open in Web Editor NEW
412.0 39.0 2.1K 1.57 MB

A Spring Framework application based on JSP, Spring MVC, Spring Data JPA, Hibernate and JDBC

License: Apache License 2.0

Java 42.70% CSS 55.20% SCSS 2.10%
spring sample springframework spring-mvc jpa hibernate spring-data-jpa mysql tomcat jetty

spring-framework-petclinic's Introduction

Spring PetClinic Sample Application

Java CI with Maven Quality Gate Status Coverage

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

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:

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-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://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 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.org.

spring-framework-petclinic's People

Contributors

albihasani94 avatar andxu avatar arey avatar babinslava avatar boly38 avatar bram-atmire avatar cbeams avatar colinbut avatar craigsdennis avatar cyrille-leclerc avatar deepalimayekar avatar dependabot[bot] avatar freemansoft avatar geminicaprograms avatar gordonad avatar helloworld123122344134 avatar liouxiao avatar lukasz-szewc avatar meltsufin avatar mklose avatar patrickcrocker avatar pinepond avatar rstoyanchev avatar srenkens avatar tduchateau avatar tejasm avatar trepel avatar verydapeng avatar vfedoriv avatar vladfau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-framework-petclinic's Issues

Vulnerable dependencies found in Spring Framework main branch

Hi Team,
I have cloned and scanned the vulnerabilities for the recent code base using OWASP dependency check and found 3 vulnerable dependencies with 2 High and 1 medium severity.
Please find the attached image for the same and waiting for your quick response.
Thanks in advance.

owasp results

The application don't compile for higher versions than JAVA8

The application don't compile for higher versions than JAVA8

Med venlig hilsen / Kind regards

Tom Stevns
Adjunkt / Assistant profressor - Computer Science

KEA – Københavns Erhvervsakademi
Copenhagen School of Design and Technology
Lygten 37
DK 2400 København NV

docker image install has buggered up menu

Repro steps:

install whatever the latest docker image is as of 22.12.16 using:
docker run -p 8080:8080 springcommunity/spring-framework-petclinic

image downloaded/started just fine. However, viewing had a couple of issues:
in chrome, instead of the menu bar items or menu dropdown, there's a white box that says "toggle navigation" and no menu items.

In the dev console I see this:
Uncaught Error: Bootstrap's JavaScript requires jQ
Screenshot 2022-12-26 at 1 15 58 PM
uery version 1.9.1 or higher, but lower than version 3
at bootstrap.min.js:6:216
at bootstrap.min.js:6:318

Firefox shows the menu items when the browser window is wide enough, and the app seems to work with them. However, shrink the width to < 922px to show the menu button and the menu button is unresponsive.

Firefox console also shows:

Uncaught Error: Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3
http://localhost:8080/webjars/bootstrap/3.3.6/js/bootstrap.min.js:6
http://localhost:8080/webjars/bootstrap/3.3.6/js/bootstrap.min.js:6

Cloning latest repo and building/running via maven worked fine.

Main class not found

Hi ,

I am new to spring framework and cloned your code. While running it on server it is giving me HTTP 404 . Can you please see
screen shot 2018-04-17 at 10 09 28 pm

new functionality remove pet from specific owner

Hi, I'm trying to add this functionality for a class job.
I remove one pet of the list of pets for one owner, save the owner and later delete the pet. This is the way I'm trying to do it, but throw a this SQL exception:

[WARNING] SQL Error: -10, SQLState: 23502
[ERROR] violación del restricción de integridad: restricción ('check') NOT NULL; SYS_CT_10117 table: PETS column: OWNER_ID
[ERROR] HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]
[WARNING] Resolved [org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement]

Any recommendations to add this functionality, or solve this problem, or documentation?

GCP

When deployed to google cloud appengine, app gets 500 server error.

URL: https://.appspot.com
From webpage:
Error: Server Error
The server encountered an error and could not complete your request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.