diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java
index c32394f140a..c01806e55e7 100644
--- a/.mvn/wrapper/MavenWrapperDownloader.java
+++ b/.mvn/wrapper/MavenWrapperDownloader.java
@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0'
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/docker-compose.yml b/docker-compose.yml
index 0f4a7fc30da..5166fe90fff 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,7 +3,10 @@ mysql:
ports:
- "3306:3306"
environment:
- - MYSQL_ROOT_PASSWORD=petclinic
+ - MYSQL_ROOT_PASSWORD=
+ - MYSQL_ALLOW_EMPTY_PASSWORD=true
+ - MYSQL_USER=petclinic
+ - MYSQL_PASSWORD=petclinic
- MYSQL_DATABASE=petclinic
volumes:
- "./conf.d:/etc/mysql/conf.d:ro"
diff --git a/mvnw b/mvnw
index d2f0ea38081..05f3faa58f6 100755
--- a/mvnw
+++ b/mvnw
@@ -8,7 +8,7 @@
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# https://www.apache.org/licenses/LICENSE-2.0'
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
diff --git a/mvnw.cmd b/mvnw.cmd
index b26ab24f039..ddd99188676 100644
--- a/mvnw.cmd
+++ b/mvnw.cmd
@@ -7,7 +7,7 @@
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
-@REM http://www.apache.org/licenses/LICENSE-2.0
+@REM https://www.apache.org/licenses/LICENSE-2.0'
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
diff --git a/pom.xml b/pom.xml
index 0e99f078693..2baea5a1214 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,16 +1,16 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0org.springframework.samplesspring-petclinic
- 2.1.0.BUILD-SNAPSHOT
+ 2.3.0.BUILD-SNAPSHOTorg.springframework.bootspring-boot-starter-parent
- 2.1.9.RELEASE
+ 2.3.0.RC1petclinic
@@ -27,8 +27,9 @@
2.2.41.8.0
- 0.8.2
-
+ 0.8.5
+ 0.0.4.RELEASE
+ 0.0.21
@@ -49,6 +50,10 @@
org.springframework.bootspring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+ org.springframework.bootspring-boot-starter-thymeleaf
@@ -57,12 +62,18 @@
org.springframework.bootspring-boot-starter-testtest
+
+
+ org.junit.vintage
+ junit-vintage-engine
+
+
-
+
- org.hsqldb
- hsqldb
+ com.h2database
+ h2runtime
@@ -103,6 +114,18 @@
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+ org.mockito
+ mockito-junit-jupiter
+ test
+
+
org.springframework.bootspring-boot-devtools
@@ -112,6 +135,54 @@
+
+ io.spring.javaformat
+ spring-javaformat-maven-plugin
+ ${spring-format.version}
+
+
+
+ validate
+
+ validate
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 3.1.1
+
+
+ com.puppycrawl.tools
+ checkstyle
+ 8.29
+
+
+ io.spring.nohttp
+ nohttp-checkstyle
+ ${nohttp-checkstyle.version}
+
+
+
+
+ nohttp-checkstyle-validation
+ validate
+
+ src/checkstyle/nohttp-checkstyle.xml
+ src/checkstyle/nohttp-checkstyle-suppressions.xml
+ UTF-8
+ ${basedir}
+ **/*
+ **/.git/**/*,**/.idea/**/*,**/target/**/,**/.flattened-pom.xml,**/*.class
+
+
+ check
+
+
+
+ org.springframework.bootspring-boot-maven-plugin
@@ -256,4 +327,60 @@
+
+
+ m2e
+
+
+ m2e.version
+
+
+
+
+
+
+
+ org.eclipse.m2e
+ lifecycle-mapping
+ 1.0.0
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ [1,)
+
+ check
+
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ [1,)
+
+ build-info
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/readme.md b/readme.md
index 34c8e8b8457..716676ed34d 100644
--- a/readme.md
+++ b/readme.md
@@ -35,14 +35,17 @@ Our issue tracker is available here: https://github.com/spring-projects/spring-p
## Database configuration
-In its default configuration, Petclinic uses an in-memory database (HSQLDB) which
-gets populated at startup with data. A similar setup is provided for MySql in case a persistent database configuration is needed.
+In its default configuration, Petclinic uses an in-memory database (H2) which
+gets populated at startup with data. The h2 console is automatically exposed at `http://localhost:8080/h2-console`
+and it is possible to inspect the content of the database using the `jdbc:h2:mem:testdb` url.
+
+A similar setup is provided for MySql in case a persistent database configuration is needed.
Note that whenever the database type is changed, the app needs to be run with a different profile: `spring.profiles.active=mysql` for MySql.
You could start MySql locally with whatever installer works for your OS, or with docker:
```
-docker run -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8
+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
```
Further documentation is provided [here](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt).
diff --git a/src/checkstyle/nohttp-checkstyle-suppressions.xml b/src/checkstyle/nohttp-checkstyle-suppressions.xml
new file mode 100644
index 00000000000..1b40e8b3fcc
--- /dev/null
+++ b/src/checkstyle/nohttp-checkstyle-suppressions.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
diff --git a/src/checkstyle/nohttp-checkstyle.xml b/src/checkstyle/nohttp-checkstyle.xml
new file mode 100644
index 00000000000..e6205127bfc
--- /dev/null
+++ b/src/checkstyle/nohttp-checkstyle.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java b/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java
index cf0c5e3010f..19125358790 100644
--- a/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java
+++ b/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java
@@ -25,11 +25,11 @@
* @author Dave Syer
*
*/
-@SpringBootApplication
+@SpringBootApplication(proxyBeanMethods = false)
public class PetClinicApplication {
- public static void main(String[] args) {
- SpringApplication.run(PetClinicApplication.class, args);
- }
+ public static void main(String[] args) {
+ SpringApplication.run(PetClinicApplication.class, args);
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java
index 8350eb744dd..4cb9ffc0c08 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java
+++ b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java
@@ -31,20 +31,21 @@
*/
@MappedSuperclass
public class BaseEntity implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer id;
- public Integer getId() {
- return id;
- }
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
- public void setId(Integer id) {
- this.id = id;
- }
+ public Integer getId() {
+ return id;
+ }
- public boolean isNew() {
- return this.id == null;
- }
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public boolean isNew() {
+ return this.id == null;
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java b/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java
index cc596a19404..088e52e81b6 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java
+++ b/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java
@@ -18,10 +18,9 @@
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
-
/**
- * Simple JavaBean domain object adds a name property to BaseEntity. Used as a base class for objects
- * needing these properties.
+ * Simple JavaBean domain object adds a name property to BaseEntity. Used as
+ * a base class for objects needing these properties.
*
* @author Ken Krebs
* @author Juergen Hoeller
@@ -29,20 +28,20 @@
@MappedSuperclass
public class NamedEntity extends BaseEntity {
- @Column(name = "name")
- private String name;
+ @Column(name = "name")
+ private String name;
- public String getName() {
- return this.name;
- }
+ public String getName() {
+ return this.name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- @Override
- public String toString() {
- return this.getName();
- }
+ @Override
+ public String toString() {
+ return this.getName();
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/Person.java b/src/main/java/org/springframework/samples/petclinic/model/Person.java
index 883376fbcdf..15fabacc3b5 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/Person.java
+++ b/src/main/java/org/springframework/samples/petclinic/model/Person.java
@@ -27,28 +27,28 @@
@MappedSuperclass
public class Person extends BaseEntity {
- @Column(name = "first_name")
- @NotEmpty
- private String firstName;
+ @Column(name = "first_name")
+ @NotEmpty
+ private String firstName;
- @Column(name = "last_name")
- @NotEmpty
- private String lastName;
+ @Column(name = "last_name")
+ @NotEmpty
+ private String lastName;
- public String getFirstName() {
- return this.firstName;
- }
+ public String getFirstName() {
+ return this.firstName;
+ }
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
- public String getLastName() {
- return this.lastName;
- }
+ public String getLastName() {
+ return this.lastName;
+ }
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/package-info.java b/src/main/java/org/springframework/samples/petclinic/model/package-info.java
index 13c1673d50f..37d6295e8a3 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/package-info.java
+++ b/src/main/java/org/springframework/samples/petclinic/model/package-info.java
@@ -18,4 +18,3 @@
* The classes in this package represent utilities used by the domain.
*/
package org.springframework.samples.petclinic.model;
-
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java
index 5b1b7fb36ec..61083bc8d50 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java
+++ b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java
@@ -45,108 +45,106 @@
@Entity
@Table(name = "owners")
public class Owner extends Person {
- @Column(name = "address")
- @NotEmpty
- private String address;
-
- @Column(name = "city")
- @NotEmpty
- private String city;
-
- @Column(name = "telephone")
- @NotEmpty
- @Digits(fraction = 0, integer = 10)
- private String telephone;
-
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
- private Set pets;
-
- public String getAddress() {
- return this.address;
- }
-
- public void setAddress(String address) {
- this.address = address;
- }
-
- public String getCity() {
- return this.city;
- }
-
- public void setCity(String city) {
- this.city = city;
- }
-
- public String getTelephone() {
- return this.telephone;
- }
-
- public void setTelephone(String telephone) {
- this.telephone = telephone;
- }
-
- protected Set getPetsInternal() {
- if (this.pets == null) {
- this.pets = new HashSet<>();
- }
- return this.pets;
- }
-
- protected void setPetsInternal(Set pets) {
- this.pets = pets;
- }
-
- public List getPets() {
- List sortedPets = new ArrayList<>(getPetsInternal());
- PropertyComparator.sort(sortedPets,
- new MutableSortDefinition("name", true, true));
- return Collections.unmodifiableList(sortedPets);
- }
-
- public void addPet(Pet pet) {
- if (pet.isNew()) {
- getPetsInternal().add(pet);
- }
- pet.setOwner(this);
- }
-
- /**
- * Return the Pet with the given name, or null if none found for this Owner.
- *
- * @param name to test
- * @return true if pet name is already in use
- */
- public Pet getPet(String name) {
- return getPet(name, false);
- }
-
- /**
- * Return the Pet with the given name, or null if none found for this Owner.
- *
- * @param name to test
- * @return true if pet name is already in use
- */
- public Pet getPet(String name, boolean ignoreNew) {
- name = name.toLowerCase();
- for (Pet pet : getPetsInternal()) {
- if (!ignoreNew || !pet.isNew()) {
- String compName = pet.getName();
- compName = compName.toLowerCase();
- if (compName.equals(name)) {
- return pet;
- }
- }
- }
- return null;
- }
-
- @Override
- public String toString() {
- return new ToStringCreator(this)
-
- .append("id", this.getId()).append("new", this.isNew())
- .append("lastName", this.getLastName())
- .append("firstName", this.getFirstName()).append("address", this.address)
- .append("city", this.city).append("telephone", this.telephone).toString();
- }
+
+ @Column(name = "address")
+ @NotEmpty
+ private String address;
+
+ @Column(name = "city")
+ @NotEmpty
+ private String city;
+
+ @Column(name = "telephone")
+ @NotEmpty
+ @Digits(fraction = 0, integer = 10)
+ private String telephone;
+
+ @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
+ private Set pets;
+
+ public String getAddress() {
+ return this.address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public String getCity() {
+ return this.city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getTelephone() {
+ return this.telephone;
+ }
+
+ public void setTelephone(String telephone) {
+ this.telephone = telephone;
+ }
+
+ protected Set getPetsInternal() {
+ if (this.pets == null) {
+ this.pets = new HashSet<>();
+ }
+ return this.pets;
+ }
+
+ protected void setPetsInternal(Set pets) {
+ this.pets = pets;
+ }
+
+ public List getPets() {
+ List sortedPets = new ArrayList<>(getPetsInternal());
+ PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true));
+ return Collections.unmodifiableList(sortedPets);
+ }
+
+ public void addPet(Pet pet) {
+ if (pet.isNew()) {
+ getPetsInternal().add(pet);
+ }
+ pet.setOwner(this);
+ }
+
+ /**
+ * Return the Pet with the given name, or null if none found for this Owner.
+ * @param name to test
+ * @return true if pet name is already in use
+ */
+ public Pet getPet(String name) {
+ return getPet(name, false);
+ }
+
+ /**
+ * Return the Pet with the given name, or null if none found for this Owner.
+ * @param name to test
+ * @return true if pet name is already in use
+ */
+ public Pet getPet(String name, boolean ignoreNew) {
+ name = name.toLowerCase();
+ for (Pet pet : getPetsInternal()) {
+ if (!ignoreNew || !pet.isNew()) {
+ String compName = pet.getName();
+ compName = compName.toLowerCase();
+ if (compName.equals(name)) {
+ return pet;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringCreator(this)
+
+ .append("id", this.getId()).append("new", this.isNew()).append("lastName", this.getLastName())
+ .append("firstName", this.getFirstName()).append("address", this.address).append("city", this.city)
+ .append("telephone", this.telephone).toString();
+ }
+
}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java
index afc2c937e65..79aa4cd9ba0 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java
+++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java
@@ -39,102 +39,107 @@
@Controller
class OwnerController {
- private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
- private final OwnerRepository owners;
- private VisitRepository visits;
-
-
- public OwnerController(OwnerRepository clinicService, VisitRepository visits) {
- this.owners = clinicService;
- this.visits = visits;
- }
-
- @InitBinder
- public void setAllowedFields(WebDataBinder dataBinder) {
- dataBinder.setDisallowedFields("id");
- }
-
- @GetMapping("/owners/new")
- public String initCreationForm(Map model) {
- Owner owner = new Owner();
- model.put("owner", owner);
- return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
- }
-
- @PostMapping("/owners/new")
- public String processCreationForm(@Valid Owner owner, BindingResult result) {
- if (result.hasErrors()) {
- return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
- } else {
- this.owners.save(owner);
- return "redirect:/owners/" + owner.getId();
- }
- }
-
- @GetMapping("/owners/find")
- public String initFindForm(Map model) {
- model.put("owner", new Owner());
- return "owners/findOwners";
- }
-
- @GetMapping("/owners")
- public String processFindForm(Owner owner, BindingResult result, Map model) {
-
- // allow parameterless GET request for /owners to return all records
- if (owner.getLastName() == null) {
- owner.setLastName(""); // empty string signifies broadest possible search
- }
-
- // find owners by last name
- Collection results = this.owners.findByLastName(owner.getLastName());
- if (results.isEmpty()) {
- // no owners found
- result.rejectValue("lastName", "notFound", "not found");
- return "owners/findOwners";
- } else if (results.size() == 1) {
- // 1 owner found
- owner = results.iterator().next();
- return "redirect:/owners/" + owner.getId();
- } else {
- // multiple owners found
- model.put("selections", results);
- return "owners/ownersList";
- }
- }
-
- @GetMapping("/owners/{ownerId}/edit")
- public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
- Owner owner = this.owners.findById(ownerId);
- model.addAttribute(owner);
- return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
- }
-
- @PostMapping("/owners/{ownerId}/edit")
- public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, @PathVariable("ownerId") int ownerId) {
- if (result.hasErrors()) {
- return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
- } else {
- owner.setId(ownerId);
- this.owners.save(owner);
- return "redirect:/owners/{ownerId}";
- }
- }
-
- /**
- * Custom handler for displaying an owner.
- *
- * @param ownerId the ID of the owner to display
- * @return a ModelMap with the model attributes for the view
- */
- @GetMapping("/owners/{ownerId}")
- public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
- ModelAndView mav = new ModelAndView("owners/ownerDetails");
- Owner owner = this.owners.findById(ownerId);
- for (Pet pet : owner.getPets()) {
- pet.setVisitsInternal(visits.findByPetId(pet.getId()));
- }
- mav.addObject(owner);
- return mav;
- }
+ private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
+
+ private final OwnerRepository owners;
+
+ private VisitRepository visits;
+
+ public OwnerController(OwnerRepository clinicService, VisitRepository visits) {
+ this.owners = clinicService;
+ this.visits = visits;
+ }
+
+ @InitBinder
+ public void setAllowedFields(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields("id");
+ }
+
+ @GetMapping("/owners/new")
+ public String initCreationForm(Map model) {
+ Owner owner = new Owner();
+ model.put("owner", owner);
+ return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
+ }
+
+ @PostMapping("/owners/new")
+ public String processCreationForm(@Valid Owner owner, BindingResult result) {
+ if (result.hasErrors()) {
+ return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
+ }
+ else {
+ this.owners.save(owner);
+ return "redirect:/owners/" + owner.getId();
+ }
+ }
+
+ @GetMapping("/owners/find")
+ public String initFindForm(Map model) {
+ model.put("owner", new Owner());
+ return "owners/findOwners";
+ }
+
+ @GetMapping("/owners")
+ public String processFindForm(Owner owner, BindingResult result, Map model) {
+
+ // allow parameterless GET request for /owners to return all records
+ if (owner.getLastName() == null) {
+ owner.setLastName(""); // empty string signifies broadest possible search
+ }
+
+ // find owners by last name
+ Collection results = this.owners.findByLastName(owner.getLastName());
+ if (results.isEmpty()) {
+ // no owners found
+ result.rejectValue("lastName", "notFound", "not found");
+ return "owners/findOwners";
+ }
+ else if (results.size() == 1) {
+ // 1 owner found
+ owner = results.iterator().next();
+ return "redirect:/owners/" + owner.getId();
+ }
+ else {
+ // multiple owners found
+ model.put("selections", results);
+ return "owners/ownersList";
+ }
+ }
+
+ @GetMapping("/owners/{ownerId}/edit")
+ public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
+ Owner owner = this.owners.findById(ownerId);
+ model.addAttribute(owner);
+ return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
+ }
+
+ @PostMapping("/owners/{ownerId}/edit")
+ public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result,
+ @PathVariable("ownerId") int ownerId) {
+ if (result.hasErrors()) {
+ return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
+ }
+ else {
+ owner.setId(ownerId);
+ this.owners.save(owner);
+ return "redirect:/owners/{ownerId}";
+ }
+ }
+
+ /**
+ * Custom handler for displaying an owner.
+ * @param ownerId the ID of the owner to display
+ * @return a ModelMap with the model attributes for the view
+ */
+ @GetMapping("/owners/{ownerId}")
+ public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
+ ModelAndView mav = new ModelAndView("owners/ownerDetails");
+ Owner owner = this.owners.findById(ownerId);
+ for (Pet pet : owner.getPets()) {
+ pet.setVisitsInternal(visits.findByPetId(pet.getId()));
+ }
+ mav.addObject(owner);
+ return mav;
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java
index a5803f36a2b..0613e928a09 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java
+++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java
@@ -23,9 +23,10 @@
import org.springframework.transaction.annotation.Transactional;
/**
- * Repository class for Owner domain objects All method names are compliant with Spring Data naming
- * conventions so this interface can easily be extended for Spring Data.
- * See: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
+ * Repository class for Owner domain objects All method names are compliant
+ * with Spring Data naming conventions so this interface can easily be extended for Spring
+ * Data. See:
+ * https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
*
* @author Ken Krebs
* @author Juergen Hoeller
@@ -34,31 +35,30 @@
*/
public interface OwnerRepository extends Repository {
- /**
- * Retrieve {@link Owner}s from the data store by last name, returning all owners
- * whose last name starts with the given name.
- * @param lastName Value to search for
- * @return a Collection of matching {@link Owner}s (or an empty Collection if none
- * found)
- */
- @Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%")
- @Transactional(readOnly = true)
- Collection findByLastName(@Param("lastName") String lastName);
+ /**
+ * Retrieve {@link Owner}s from the data store by last name, returning all owners
+ * whose last name starts with the given name.
+ * @param lastName Value to search for
+ * @return a Collection of matching {@link Owner}s (or an empty Collection if none
+ * found)
+ */
+ @Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%")
+ @Transactional(readOnly = true)
+ Collection findByLastName(@Param("lastName") String lastName);
- /**
- * Retrieve an {@link Owner} from the data store by id.
- * @param id the id to search for
- * @return the {@link Owner} if found
- */
- @Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
- @Transactional(readOnly = true)
- Owner findById(@Param("id") Integer id);
-
- /**
- * Save an {@link Owner} to the data store, either inserting or updating it.
- * @param owner the {@link Owner} to save
- */
- void save(Owner owner);
+ /**
+ * Retrieve an {@link Owner} from the data store by id.
+ * @param id the id to search for
+ * @return the {@link Owner} if found
+ */
+ @Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
+ @Transactional(readOnly = true)
+ Owner findById(@Param("id") Integer id);
+ /**
+ * Save an {@link Owner} to the data store, either inserting or updating it.
+ * @param owner the {@link Owner} to save
+ */
+ void save(Owner owner);
}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java
index 0bd04b7721f..2b68005fd64 100755
--- a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java
+++ b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java
@@ -48,66 +48,65 @@
@Table(name = "pets")
public class Pet extends NamedEntity {
- @Column(name = "birth_date")
- @DateTimeFormat(pattern = "yyyy-MM-dd")
- private LocalDate birthDate;
-
- @ManyToOne
- @JoinColumn(name = "type_id")
- private PetType type;
-
- @ManyToOne
- @JoinColumn(name = "owner_id")
- private Owner owner;
-
- @Transient
- private Set visits = new LinkedHashSet<>();
-
- public void setBirthDate(LocalDate birthDate) {
- this.birthDate = birthDate;
- }
-
- public LocalDate getBirthDate() {
- return this.birthDate;
- }
-
- public PetType getType() {
- return this.type;
- }
-
- public void setType(PetType type) {
- this.type = type;
- }
-
- public Owner getOwner() {
- return this.owner;
- }
-
- protected void setOwner(Owner owner) {
- this.owner = owner;
- }
-
- protected Set getVisitsInternal() {
- if (this.visits == null) {
- this.visits = new HashSet<>();
- }
- return this.visits;
- }
-
- protected void setVisitsInternal(Collection visits) {
- this.visits = new LinkedHashSet<>(visits);
- }
-
- public List getVisits() {
- List sortedVisits = new ArrayList<>(getVisitsInternal());
- PropertyComparator.sort(sortedVisits,
- new MutableSortDefinition("date", false, false));
- return Collections.unmodifiableList(sortedVisits);
- }
-
- public void addVisit(Visit visit) {
- getVisitsInternal().add(visit);
- visit.setPetId(this.getId());
- }
+ @Column(name = "birth_date")
+ @DateTimeFormat(pattern = "yyyy-MM-dd")
+ private LocalDate birthDate;
+
+ @ManyToOne
+ @JoinColumn(name = "type_id")
+ private PetType type;
+
+ @ManyToOne
+ @JoinColumn(name = "owner_id")
+ private Owner owner;
+
+ @Transient
+ private Set visits = new LinkedHashSet<>();
+
+ public void setBirthDate(LocalDate birthDate) {
+ this.birthDate = birthDate;
+ }
+
+ public LocalDate getBirthDate() {
+ return this.birthDate;
+ }
+
+ public PetType getType() {
+ return this.type;
+ }
+
+ public void setType(PetType type) {
+ this.type = type;
+ }
+
+ public Owner getOwner() {
+ return this.owner;
+ }
+
+ protected void setOwner(Owner owner) {
+ this.owner = owner;
+ }
+
+ protected Set getVisitsInternal() {
+ if (this.visits == null) {
+ this.visits = new HashSet<>();
+ }
+ return this.visits;
+ }
+
+ protected void setVisitsInternal(Collection visits) {
+ this.visits = new LinkedHashSet<>(visits);
+ }
+
+ public List getVisits() {
+ List sortedVisits = new ArrayList<>(getVisitsInternal());
+ PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false));
+ return Collections.unmodifiableList(sortedVisits);
+ }
+
+ public void addVisit(Visit visit) {
+ getVisitsInternal().add(visit);
+ visit.setPetId(this.getId());
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java
index 0107aa8a93f..a55e599afbe 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java
+++ b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java
@@ -34,76 +34,80 @@
@RequestMapping("/owners/{ownerId}")
class PetController {
- private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";
- private final PetRepository pets;
- private final OwnerRepository owners;
-
- public PetController(PetRepository pets, OwnerRepository owners) {
- this.pets = pets;
- this.owners = owners;
- }
-
- @ModelAttribute("types")
- public Collection populatePetTypes() {
- return this.pets.findPetTypes();
- }
-
- @ModelAttribute("owner")
- public Owner findOwner(@PathVariable("ownerId") int ownerId) {
- return this.owners.findById(ownerId);
- }
-
- @InitBinder("owner")
- public void initOwnerBinder(WebDataBinder dataBinder) {
- dataBinder.setDisallowedFields("id");
- }
-
- @InitBinder("pet")
- public void initPetBinder(WebDataBinder dataBinder) {
- dataBinder.setValidator(new PetValidator());
- }
-
- @GetMapping("/pets/new")
- public String initCreationForm(Owner owner, ModelMap model) {
- Pet pet = new Pet();
- owner.addPet(pet);
- model.put("pet", pet);
- return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
- }
-
- @PostMapping("/pets/new")
- public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model) {
- if (StringUtils.hasLength(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null){
- result.rejectValue("name", "duplicate", "already exists");
- }
- owner.addPet(pet);
- if (result.hasErrors()) {
- model.put("pet", pet);
- return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
- } else {
- this.pets.save(pet);
- return "redirect:/owners/{ownerId}";
- }
- }
-
- @GetMapping("/pets/{petId}/edit")
- public String initUpdateForm(@PathVariable("petId") int petId, ModelMap model) {
- Pet pet = this.pets.findById(petId);
- model.put("pet", pet);
- return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
- }
-
- @PostMapping("/pets/{petId}/edit")
- public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owner, ModelMap model) {
- if (result.hasErrors()) {
- pet.setOwner(owner);
- model.put("pet", pet);
- return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
- } else {
- owner.addPet(pet);
- this.pets.save(pet);
- return "redirect:/owners/{ownerId}";
- }
- }
+ private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";
+
+ private final PetRepository pets;
+
+ private final OwnerRepository owners;
+
+ public PetController(PetRepository pets, OwnerRepository owners) {
+ this.pets = pets;
+ this.owners = owners;
+ }
+
+ @ModelAttribute("types")
+ public Collection populatePetTypes() {
+ return this.pets.findPetTypes();
+ }
+
+ @ModelAttribute("owner")
+ public Owner findOwner(@PathVariable("ownerId") int ownerId) {
+ return this.owners.findById(ownerId);
+ }
+
+ @InitBinder("owner")
+ public void initOwnerBinder(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields("id");
+ }
+
+ @InitBinder("pet")
+ public void initPetBinder(WebDataBinder dataBinder) {
+ dataBinder.setValidator(new PetValidator());
+ }
+
+ @GetMapping("/pets/new")
+ public String initCreationForm(Owner owner, ModelMap model) {
+ Pet pet = new Pet();
+ owner.addPet(pet);
+ model.put("pet", pet);
+ return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
+ }
+
+ @PostMapping("/pets/new")
+ public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model) {
+ if (StringUtils.hasLength(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null) {
+ result.rejectValue("name", "duplicate", "already exists");
+ }
+ owner.addPet(pet);
+ if (result.hasErrors()) {
+ model.put("pet", pet);
+ return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
+ }
+ else {
+ this.pets.save(pet);
+ return "redirect:/owners/{ownerId}";
+ }
+ }
+
+ @GetMapping("/pets/{petId}/edit")
+ public String initUpdateForm(@PathVariable("petId") int petId, ModelMap model) {
+ Pet pet = this.pets.findById(petId);
+ model.put("pet", pet);
+ return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
+ }
+
+ @PostMapping("/pets/{petId}/edit")
+ public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owner, ModelMap model) {
+ if (result.hasErrors()) {
+ pet.setOwner(owner);
+ model.put("pet", pet);
+ return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
+ }
+ else {
+ owner.addPet(pet);
+ this.pets.save(pet);
+ return "redirect:/owners/{ownerId}";
+ }
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetRepository.java b/src/main/java/org/springframework/samples/petclinic/owner/PetRepository.java
index 0d483b7ad53..9d25b095bae 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/PetRepository.java
+++ b/src/main/java/org/springframework/samples/petclinic/owner/PetRepository.java
@@ -22,9 +22,10 @@
import org.springframework.transaction.annotation.Transactional;
/**
- * Repository class for Pet domain objects All method names are compliant with Spring Data naming
- * conventions so this interface can easily be extended for Spring Data.
- * See: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
+ * Repository class for Pet domain objects All method names are compliant
+ * with Spring Data naming conventions so this interface can easily be extended for Spring
+ * Data. See:
+ * https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
*
* @author Ken Krebs
* @author Juergen Hoeller
@@ -33,27 +34,26 @@
*/
public interface PetRepository extends Repository {
- /**
- * Retrieve all {@link PetType}s from the data store.
- * @return a Collection of {@link PetType}s.
- */
- @Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
- @Transactional(readOnly = true)
- List findPetTypes();
-
- /**
- * Retrieve a {@link Pet} from the data store by id.
- * @param id the id to search for
- * @return the {@link Pet} if found
- */
- @Transactional(readOnly = true)
- Pet findById(Integer id);
-
- /**
- * Save a {@link Pet} to the data store, either inserting or updating it.
- * @param pet the {@link Pet} to save
- */
- void save(Pet pet);
+ /**
+ * Retrieve all {@link PetType}s from the data store.
+ * @return a Collection of {@link PetType}s.
+ */
+ @Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
+ @Transactional(readOnly = true)
+ List findPetTypes();
+
+ /**
+ * Retrieve a {@link Pet} from the data store by id.
+ * @param id the id to search for
+ * @return the {@link Pet} if found
+ */
+ @Transactional(readOnly = true)
+ Pet findById(Integer id);
+
+ /**
+ * Save a {@link Pet} to the data store, either inserting or updating it.
+ * @param pet the {@link Pet} to save
+ */
+ void save(Pet pet);
}
-
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetType.java b/src/main/java/org/springframework/samples/petclinic/owner/PetType.java
index 19c27bee303..6f0aa58d377 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/PetType.java
+++ b/src/main/java/org/springframework/samples/petclinic/owner/PetType.java
@@ -21,8 +21,7 @@
import org.springframework.samples.petclinic.model.NamedEntity;
/**
- * @author Juergen Hoeller
- * Can be Cat, Dog, Hamster...
+ * @author Juergen Hoeller Can be Cat, Dog, Hamster...
*/
@Entity
@Table(name = "types")
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetTypeFormatter.java b/src/main/java/org/springframework/samples/petclinic/owner/PetTypeFormatter.java
index 4423482a3af..4940bcb38e7 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/PetTypeFormatter.java
+++ b/src/main/java/org/springframework/samples/petclinic/owner/PetTypeFormatter.java
@@ -24,9 +24,10 @@
import org.springframework.stereotype.Component;
/**
- * Instructs Spring MVC on how to parse and print elements of type 'PetType'. Starting from Spring 3.0, Formatters have
- * come as an improvement in comparison to legacy PropertyEditors. See the following links for more details: - The
- * Spring ref doc: https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#format
+ * Instructs Spring MVC on how to parse and print elements of type 'PetType'. Starting
+ * from Spring 3.0, Formatters have come as an improvement in comparison to legacy
+ * PropertyEditors. See the following links for more details: - The Spring ref doc:
+ * https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#format
*
* @author Mark Fisher
* @author Juergen Hoeller
@@ -35,28 +36,27 @@
@Component
public class PetTypeFormatter implements Formatter {
- private final PetRepository pets;
-
-
- @Autowired
- public PetTypeFormatter(PetRepository pets) {
- this.pets = pets;
- }
-
- @Override
- public String print(PetType petType, Locale locale) {
- return petType.getName();
- }
-
- @Override
- public PetType parse(String text, Locale locale) throws ParseException {
- Collection findPetTypes = this.pets.findPetTypes();
- for (PetType type : findPetTypes) {
- if (type.getName().equals(text)) {
- return type;
- }
- }
- throw new ParseException("type not found: " + text, 0);
- }
+ private final PetRepository pets;
+
+ @Autowired
+ public PetTypeFormatter(PetRepository pets) {
+ this.pets = pets;
+ }
+
+ @Override
+ public String print(PetType petType, Locale locale) {
+ return petType.getName();
+ }
+
+ @Override
+ public PetType parse(String text, Locale locale) throws ParseException {
+ Collection findPetTypes = this.pets.findPetTypes();
+ for (PetType type : findPetTypes) {
+ if (type.getName().equals(text)) {
+ return type;
+ }
+ }
+ throw new ParseException("type not found: " + text, 0);
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetValidator.java b/src/main/java/org/springframework/samples/petclinic/owner/PetValidator.java
index 3e8438b3306..e1370b42803 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/PetValidator.java
+++ b/src/main/java/org/springframework/samples/petclinic/owner/PetValidator.java
@@ -22,7 +22,8 @@
/**
* Validator for Pet forms.
*
- * We're not using Bean Validation annotations here because it is easier to define such validation rule in Java.
+ * We're not using Bean Validation annotations here because it is easier to define such
+ * validation rule in Java.
*
*
* @author Ken Krebs
@@ -30,35 +31,34 @@
*/
public class PetValidator implements Validator {
- private static final String REQUIRED = "required";
+ private static final String REQUIRED = "required";
- @Override
- public void validate(Object obj, Errors errors) {
- Pet pet = (Pet) obj;
- String name = pet.getName();
- // name validation
- if (!StringUtils.hasLength(name)) {
- errors.rejectValue("name", REQUIRED, REQUIRED);
- }
+ @Override
+ public void validate(Object obj, Errors errors) {
+ Pet pet = (Pet) obj;
+ String name = pet.getName();
+ // name validation
+ if (!StringUtils.hasLength(name)) {
+ errors.rejectValue("name", REQUIRED, REQUIRED);
+ }
- // type validation
- if (pet.isNew() && pet.getType() == null) {
- errors.rejectValue("type", REQUIRED, REQUIRED);
- }
+ // type validation
+ if (pet.isNew() && pet.getType() == null) {
+ errors.rejectValue("type", REQUIRED, REQUIRED);
+ }
- // birth date validation
- if (pet.getBirthDate() == null) {
- errors.rejectValue("birthDate", REQUIRED, REQUIRED);
- }
- }
-
- /**
- * This Validator validates *just* Pet instances
- */
- @Override
- public boolean supports(Class> clazz) {
- return Pet.class.isAssignableFrom(clazz);
- }
+ // birth date validation
+ if (pet.getBirthDate() == null) {
+ errors.rejectValue("birthDate", REQUIRED, REQUIRED);
+ }
+ }
+ /**
+ * This Validator validates *just* Pet instances
+ */
+ @Override
+ public boolean supports(Class> clazz) {
+ return Pet.class.isAssignableFrom(clazz);
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java b/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java
index c6dfc7fc755..37598031296 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java
+++ b/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java
@@ -40,55 +40,53 @@
@Controller
class VisitController {
- private final VisitRepository visits;
- private final PetRepository pets;
+ private final VisitRepository visits;
+ private final PetRepository pets;
- public VisitController(VisitRepository visits, PetRepository pets) {
- this.visits = visits;
- this.pets = pets;
- }
+ public VisitController(VisitRepository visits, PetRepository pets) {
+ this.visits = visits;
+ this.pets = pets;
+ }
- @InitBinder
- public void setAllowedFields(WebDataBinder dataBinder) {
- dataBinder.setDisallowedFields("id");
- }
+ @InitBinder
+ public void setAllowedFields(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields("id");
+ }
- /**
- * Called before each and every @RequestMapping annotated method.
- * 2 goals:
- * - Make sure we always have fresh data
- * - Since we do not use the session scope, make sure that Pet object always has an id
- * (Even though id is not part of the form fields)
- *
- * @param petId
- * @return Pet
- */
- @ModelAttribute("visit")
- public Visit loadPetWithVisit(@PathVariable("petId") int petId, Map model) {
- Pet pet = this.pets.findById(petId);
- pet.setVisitsInternal(this.visits.findByPetId(petId));
- model.put("pet", pet);
- Visit visit = new Visit();
- pet.addVisit(visit);
- return visit;
- }
+ /**
+ * Called before each and every @RequestMapping annotated method. 2 goals: - Make sure
+ * we always have fresh data - Since we do not use the session scope, make sure that
+ * Pet object always has an id (Even though id is not part of the form fields)
+ * @param petId
+ * @return Pet
+ */
+ @ModelAttribute("visit")
+ public Visit loadPetWithVisit(@PathVariable("petId") int petId, Map model) {
+ Pet pet = this.pets.findById(petId);
+ pet.setVisitsInternal(this.visits.findByPetId(petId));
+ model.put("pet", pet);
+ Visit visit = new Visit();
+ pet.addVisit(visit);
+ return visit;
+ }
- // Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called
- @GetMapping("/owners/*/pets/{petId}/visits/new")
- public String initNewVisitForm(@PathVariable("petId") int petId, Map model) {
- return "pets/createOrUpdateVisitForm";
- }
+ // Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called
+ @GetMapping("/owners/*/pets/{petId}/visits/new")
+ public String initNewVisitForm(@PathVariable("petId") int petId, Map model) {
+ return "pets/createOrUpdateVisitForm";
+ }
- // Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called
- @PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
- public String processNewVisitForm(@Valid Visit visit, BindingResult result) {
- if (result.hasErrors()) {
- return "pets/createOrUpdateVisitForm";
- } else {
- this.visits.save(visit);
- return "redirect:/owners/{ownerId}";
- }
- }
+ // Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called
+ @PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
+ public String processNewVisitForm(@Valid Visit visit, BindingResult result) {
+ if (result.hasErrors()) {
+ return "pets/createOrUpdateVisitForm";
+ }
+ else {
+ this.visits.save(visit);
+ return "redirect:/owners/{ownerId}";
+ }
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java b/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java
index 9d4a53c6480..0a96582c9be 100755
--- a/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java
+++ b/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java
@@ -16,37 +16,40 @@
package org.springframework.samples.petclinic.system;
+import javax.cache.configuration.MutableConfiguration;
+
import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import javax.cache.configuration.MutableConfiguration;
-
/**
- * Cache configuration intended for caches providing the JCache API. This configuration creates the used cache for the
- * application and enables statistics that become accessible via JMX.
+ * Cache configuration intended for caches providing the JCache API. This configuration
+ * creates the used cache for the application and enables statistics that become
+ * accessible via JMX.
*/
-@Configuration
+@Configuration(proxyBeanMethods = false)
@EnableCaching
class CacheConfiguration {
- @Bean
- public JCacheManagerCustomizer petclinicCacheConfigurationCustomizer() {
- return cm -> {
- cm.createCache("vets", cacheConfiguration());
- };
- }
+ @Bean
+ public JCacheManagerCustomizer petclinicCacheConfigurationCustomizer() {
+ return cm -> {
+ cm.createCache("vets", cacheConfiguration());
+ };
+ }
- /**
- * Create a simple configuration that enable statistics via the JCache programmatic configuration API.
- *
- * Within the configuration object that is provided by the JCache API standard, there is only a very limited set of
- * configuration options. The really relevant configuration options (like the size limit) must be set via a
- * configuration mechanism that is provided by the selected JCache implementation.
- */
- private javax.cache.configuration.Configuration