From 80269539e27062592f4c28b0d5498f38fbc2d578 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Sun, 8 Jan 2017 15:45:20 +0000 Subject: [PATCH 01/30] Configure caching properly to avoid error in vets --- .../samples/petclinic/vet/Specialty.java | 4 ++- .../samples/petclinic/vet/Vet.java | 9 ++--- src/main/resources/application.properties | 1 + .../system/CrashControllerTests.java | 34 ++++++------------- .../system/ProductionConfigurationTests.java | 23 +++++++++++++ 5 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java b/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java index 826e04afc..5691c2434 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java @@ -15,6 +15,8 @@ */ package org.springframework.samples.petclinic.vet; +import java.io.Serializable; + import javax.persistence.Entity; import javax.persistence.Table; @@ -27,6 +29,6 @@ import org.springframework.samples.petclinic.model.NamedEntity; */ @Entity @Table(name = "specialties") -public class Specialty extends NamedEntity { +public class Specialty extends NamedEntity implements Serializable { } diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java index 829423782..3cde3d1bf 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java @@ -15,6 +15,7 @@ */ package org.springframework.samples.petclinic.vet; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -43,11 +44,10 @@ import org.springframework.samples.petclinic.model.Person; */ @Entity @Table(name = "vets") -public class Vet extends Person { +public class Vet extends Person implements Serializable { @ManyToMany(fetch = FetchType.EAGER) - @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), - inverseJoinColumns = @JoinColumn(name = "specialty_id")) + @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), inverseJoinColumns = @JoinColumn(name = "specialty_id")) private Set specialties; protected Set getSpecialtiesInternal() { @@ -64,7 +64,8 @@ public class Vet extends Person { @XmlElement public List getSpecialties() { List sortedSpecs = new ArrayList<>(getSpecialtiesInternal()); - PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true)); + PropertyComparator.sort(sortedSpecs, + new MutableSortDefinition("name", true, true)); return Collections.unmodifiableList(sortedSpecs); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3562d7d03..cd1aea2cd 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,3 +22,4 @@ logging.level.org.springframework=INFO # Active Spring profiles spring.profiles.active=production +spring.cache.cache-names=vets \ No newline at end of file diff --git a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java b/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java index 161769254..3f108bfe9 100644 --- a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java @@ -1,20 +1,19 @@ package org.springframework.samples.petclinic.system; -import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.samples.petclinic.PetClinicApplication; -import org.springframework.samples.petclinic.system.CrashController; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; /** * Test class for {@link CrashController} @@ -22,31 +21,18 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Colin But */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = PetClinicApplication.class) -@WebAppConfiguration // Waiting https://github.com/spring-projects/spring-boot/issues/5574 @Ignore +@WebMvcTest(controllers = CrashController.class) public class CrashControllerTests { @Autowired - private CrashController crashController; - private MockMvc mockMvc; - @Before - public void setup() { - this.mockMvc = MockMvcBuilders - .standaloneSetup(crashController) - //.setHandlerExceptionResolvers(new SimpleMappingExceptionResolver()) - .build(); - } - @Test public void testTriggerException() throws Exception { - mockMvc.perform(get("/oups")) - .andExpect(view().name("exception")) - .andExpect(model().attributeExists("exception")) - .andExpect(forwardedUrl("exception")) - .andExpect(status().isOk()); + mockMvc.perform(get("/oups")).andExpect(view().name("exception")) + .andExpect(model().attributeExists("exception")) + .andExpect(forwardedUrl("exception")).andExpect(status().isOk()); } } diff --git a/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java b/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java new file mode 100644 index 000000000..9636e3623 --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java @@ -0,0 +1,23 @@ +package org.springframework.samples.petclinic.system; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.samples.petclinic.vet.VetRepository; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ProductionConfigurationTests { + + @Autowired + private VetRepository vets; + + @Test + public void testFindAll() throws Exception { + vets.findAll(); + vets.findAll(); // served from cache + } +} From 90b8df9319acfbb053cdcd6f919379ae8b723ffa Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 31 Jan 2017 15:51:55 +0000 Subject: [PATCH 02/30] Update to 1.5.1 --- pom.xml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index e842808d8..82e78e181 100644 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,12 @@ 4.0.0 org.springframework.samples spring-petclinic - 1.4.2 + 1.5.1 org.springframework.boot spring-boot-starter-parent - 1.4.2.RELEASE + 1.5.1.RELEASE petclinic @@ -28,7 +28,6 @@ 1.8.0 3.0.2.RELEASE - 2.0.4 2.7 @@ -57,8 +56,8 @@ spring-boot-starter-thymeleaf - org.codehaus.groovy - groovy + nz.net.ultraq.thymeleaf + thymeleaf-layout-dialect From e8882e8b279d98c68ba9901f8135b308034830d3 Mon Sep 17 00:00:00 2001 From: Huang YunKun Date: Sun, 18 Dec 2016 10:51:17 +0800 Subject: [PATCH 03/30] Update CacheConfig link --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 74824e378..549af20b7 100644 --- a/readme.md +++ b/readme.md @@ -60,7 +60,7 @@ File -> Import -> Maven -> Existing Maven project |--------------------------|---| |The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) | |Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/resources) | -|Caching | EhCache [CacheConfig](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/config/CacheConfig.java) | +|Caching | EhCache [CacheConfig](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java) | ## Interesting Spring Petclinic branches and forks From c7657df854121ba4fdb7641bd9a8f2ee5f9cd346 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 2 Feb 2017 16:04:52 +0000 Subject: [PATCH 04/30] Remove ehcache (at least temporarily) The fact that it was still there on the classpath means it needs to be configured (and fails silently if you don't). Removed to give us some tmie to reconsider. --- pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pom.xml b/pom.xml index 82e78e181..ca1a4c74b 100644 --- a/pom.xml +++ b/pom.xml @@ -79,16 +79,6 @@ runtime - - - javax.cache - cache-api - - - org.ehcache - ehcache - - org.webjars From 126bd97971a510506d48652822f739ff95b99165 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 3 Feb 2017 08:36:08 +0100 Subject: [PATCH 05/30] Polish --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 549af20b7..a94320b6d 100644 --- a/readme.md +++ b/readme.md @@ -60,7 +60,7 @@ File -> Import -> Maven -> Existing Maven project |--------------------------|---| |The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) | |Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/resources) | -|Caching | EhCache [CacheConfig](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java) | +|Caching | [CacheConfig](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java) | ## Interesting Spring Petclinic branches and forks From d2ec37149640ecc0cf5ff6d5a03c6800f2033441 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 3 Feb 2017 08:36:48 +0100 Subject: [PATCH 06/30] Restore actuator access with Spring Boot 1.5 --- src/main/resources/application.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index cd1aea2cd..cff6d780d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -14,6 +14,7 @@ spring.messages.basename=messages/messages # Actuator / Management management.contextPath=/manage +management.security.enabled=false # Logging logging.level.org.springframework=INFO @@ -22,4 +23,4 @@ logging.level.org.springframework=INFO # Active Spring profiles spring.profiles.active=production -spring.cache.cache-names=vets \ No newline at end of file +spring.cache.cache-names=vets From be13722cc5d851fa23be672d031ab25d54316f05 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 3 Feb 2017 08:37:02 +0100 Subject: [PATCH 07/30] Polish --- src/main/resources/application.properties | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index cff6d780d..ddb57e3e3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,4 +23,6 @@ logging.level.org.springframework=INFO # Active Spring profiles spring.profiles.active=production + +# Caching spring.cache.cache-names=vets From 0a51540ad04b48b5b18fd6fd400363fc02512134 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 3 Feb 2017 10:02:07 +0000 Subject: [PATCH 08/30] Fix serializability of Vet --- .../samples/petclinic/model/BaseEntity.java | 7 ++- .../samples/petclinic/vet/Vet.java | 3 +- src/main/resources/application.properties | 1 + .../samples/petclinic/vet/VetTests.java | 43 +++++++++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/test/java/org/springframework/samples/petclinic/vet/VetTests.java 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 14603c1ff..d929997d3 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java +++ b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java @@ -15,19 +15,22 @@ */ package org.springframework.samples.petclinic.model; +import java.io.Serializable; + import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.MappedSuperclass; /** - * Simple JavaBean domain object with an id property. Used as a base class for objects needing this property. + * Simple JavaBean domain object with an id property. Used as a base class for objects + * needing this property. * * @author Ken Krebs * @author Juergen Hoeller */ @MappedSuperclass -public class BaseEntity { +public class BaseEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) protected Integer id; diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java index 3cde3d1bf..43aecc41e 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java @@ -15,7 +15,6 @@ */ package org.springframework.samples.petclinic.vet; -import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -44,7 +43,7 @@ import org.springframework.samples.petclinic.model.Person; */ @Entity @Table(name = "vets") -public class Vet extends Person implements Serializable { +public class Vet extends Person { @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), inverseJoinColumns = @JoinColumn(name = "specialty_id")) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ddb57e3e3..fb3e513c3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -14,6 +14,7 @@ spring.messages.basename=messages/messages # Actuator / Management management.contextPath=/manage +# Spring Boot 1.5 makes actuator secure by default management.security.enabled=false # Logging diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java new file mode 100644 index 000000000..de3a7b9bb --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java @@ -0,0 +1,43 @@ +/* + * Copyright 2016-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.samples.petclinic.vet; + +import org.junit.Test; + +import org.springframework.util.SerializationUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Dave Syer + * + */ +public class VetTests { + + @Test + public void testSerialization() { + Vet vet = new Vet(); + vet.setFirstName("Zaphod"); + vet.setLastName("Beeblebrox"); + vet.setId(123); + Vet other = (Vet) SerializationUtils + .deserialize(SerializationUtils.serialize(vet)); + assertThat(other.getFirstName()).isEqualTo(vet.getFirstName()); + assertThat(other.getLastName()).isEqualTo(vet.getLastName()); + assertThat(other.getId()).isEqualTo(vet.getId()); + } + +} From 63dadcc07f5f28e40afc02dca5e779d96dc018e6 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 3 Feb 2017 10:04:34 +0000 Subject: [PATCH 09/30] Make all entity fields private Encapsulation is better that way (and tere is a getter for all of them anyway). --- .../samples/petclinic/model/BaseEntity.java | 2 +- .../samples/petclinic/model/Person.java | 5 ++- .../samples/petclinic/owner/Pet.java | 33 ++++++++++--------- 3 files changed, 20 insertions(+), 20 deletions(-) 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 d929997d3..86cc21092 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java +++ b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java @@ -33,7 +33,7 @@ import javax.persistence.MappedSuperclass; public class BaseEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - protected Integer id; + private Integer id; public Integer getId() { return id; 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 d3e03c0dd..4cb7481e0 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Person.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Person.java @@ -30,11 +30,11 @@ public class Person extends BaseEntity { @Column(name = "first_name") @NotEmpty - protected String firstName; + private String firstName; @Column(name = "last_name") @NotEmpty - protected String lastName; + private String lastName; public String getFirstName() { return this.firstName; @@ -52,5 +52,4 @@ public class Person extends BaseEntity { this.lastName = lastName; } - } 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 5b4e31790..e8df85e91 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java @@ -15,11 +15,13 @@ */ package org.springframework.samples.petclinic.owner; -import org.springframework.beans.support.MutableSortDefinition; -import org.springframework.beans.support.PropertyComparator; -import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.samples.petclinic.model.NamedEntity; -import org.springframework.samples.petclinic.visit.Visit; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -29,16 +31,14 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; - import javax.persistence.Temporal; import javax.persistence.TemporalType; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; + +import org.springframework.beans.support.MutableSortDefinition; +import org.springframework.beans.support.PropertyComparator; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.samples.petclinic.model.NamedEntity; +import org.springframework.samples.petclinic.visit.Visit; /** * Simple business object representing a pet. @@ -64,7 +64,7 @@ public class Pet extends NamedEntity { @JoinColumn(name = "owner_id") private Owner owner; - @OneToMany(cascade = CascadeType.ALL, mappedBy="petId", fetch = FetchType.EAGER) + @OneToMany(cascade = CascadeType.ALL, mappedBy = "petId", fetch = FetchType.EAGER) private Set visits = new LinkedHashSet<>(); public void setBirthDate(Date birthDate) { @@ -104,13 +104,14 @@ public class Pet extends NamedEntity { public List getVisits() { List sortedVisits = new ArrayList<>(getVisitsInternal()); - PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false)); + PropertyComparator.sort(sortedVisits, + new MutableSortDefinition("date", false, false)); return Collections.unmodifiableList(sortedVisits); } public void addVisit(Visit visit) { getVisitsInternal().add(visit); - visit.setPetId(this.id); + visit.setPetId(this.getId()); } } From 443d35eae23c874ed38305fbe75216339c41beaf Mon Sep 17 00:00:00 2001 From: Henri Tremblay Date: Thu, 16 Feb 2017 15:08:30 -0500 Subject: [PATCH 10/30] Put Ehcache back --- pom.xml | 10 ++++++++ .../samples/petclinic/system/CacheConfig.java | 24 +++++++++++++++---- src/main/resources/application.properties | 3 --- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index ca1a4c74b..82e78e181 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,16 @@ runtime + + + javax.cache + cache-api + + + org.ehcache + ehcache + + org.webjars diff --git a/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java b/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java index 8798bfb50..4bc23bbe6 100755 --- a/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java +++ b/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java @@ -1,14 +1,30 @@ package org.springframework.samples.petclinic.system; +import javax.cache.configuration.Configuration; +import javax.cache.configuration.MutableConfiguration; + +import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer; import org.springframework.cache.annotation.EnableCaching; -import org.springframework.context.annotation.Configuration; +import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.context.annotation.Profile; /** - * Cache could be disable in unit test. + * Cache could be disabled in unit test. */ -@Configuration +@org.springframework.context.annotation.Configuration @EnableCaching @Profile("production") -class CacheConfig { +class CacheConfig implements CacheManagerCustomizer { + + @Override + public void customize(JCacheCacheManager cacheManager) { + Configuration cacheConfiguration = createCacheConfiguration(); + cacheManager.getCacheManager().createCache("vets", cacheConfiguration); + } + + private Configuration createCacheConfiguration() { + // Create a cache using infinite heap. A real application will want to use an implementation dependent + // configuration that will better fit your needs + return new MutableConfiguration<>().setStatisticsEnabled(true); + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index fb3e513c3..fb07c6c50 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -24,6 +24,3 @@ logging.level.org.springframework=INFO # Active Spring profiles spring.profiles.active=production - -# Caching -spring.cache.cache-names=vets From 75912a06c5613a2ea1305ad4d8ad6bc4be7765ce Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 17 Feb 2017 12:30:57 +0100 Subject: [PATCH 11/30] Polish contribution Closes gh-229 --- pom.xml | 2 +- .../samples/petclinic/system/CacheConfig.java | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 82e78e181..d879eb929 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,7 @@ runtime - + javax.cache cache-api diff --git a/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java b/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java index 4bc23bbe6..13e194c35 100755 --- a/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java +++ b/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java @@ -3,9 +3,9 @@ package org.springframework.samples.petclinic.system; import javax.cache.configuration.Configuration; import javax.cache.configuration.MutableConfiguration; -import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer; +import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer; import org.springframework.cache.annotation.EnableCaching; -import org.springframework.cache.jcache.JCacheCacheManager; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Profile; /** @@ -14,17 +14,19 @@ import org.springframework.context.annotation.Profile; @org.springframework.context.annotation.Configuration @EnableCaching @Profile("production") -class CacheConfig implements CacheManagerCustomizer { +class CacheConfig { - @Override - public void customize(JCacheCacheManager cacheManager) { - Configuration cacheConfiguration = createCacheConfiguration(); - cacheManager.getCacheManager().createCache("vets", cacheConfiguration); + @Bean + public JCacheManagerCustomizer cacheManagerCustomizer() { + return cm -> { + Configuration cacheConfiguration = createCacheConfiguration(); + cm.createCache("vets", cacheConfiguration); + }; } private Configuration createCacheConfiguration() { - // Create a cache using infinite heap. A real application will want to use an implementation dependent - // configuration that will better fit your needs + // Create a cache using infinite heap. A real application will want to use an + // implementation dependent configuration that will better fit your needs return new MutableConfiguration<>().setStatisticsEnabled(true); } } From fd1c742d4f8d193eb935519909c15302b783cd52 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Mon, 6 Mar 2017 08:19:28 +0100 Subject: [PATCH 12/30] Do not fail maven build when git directing is missing --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index d879eb929..ff677d097 100644 --- a/pom.xml +++ b/pom.xml @@ -176,6 +176,7 @@ true ${project.build.outputDirectory}/git.properties + false From ffa967c94b65a70ea6d3b44275632821838d9fd3 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Wed, 12 Apr 2017 21:41:00 +0200 Subject: [PATCH 13/30] spring-petclinic-angular1 repo renamed to spring-petclinic-angularjs --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index a94320b6d..ac30d6392 100644 --- a/readme.md +++ b/readme.md @@ -77,7 +77,7 @@ there. |----------------|-------------------| | [spring-framework-petclinic](https://github.com/spring-petclinic/spring-framework-petclinic) | Spring Framework XML configuration, JSP pages, 3 persistence layers: JDBC, JPA and Spring Data JPA | | [javaconfig branch](https://github.com/spring-petclinic/spring-framework-petclinic/tree/javaconfig) | Same frameworks as the [spring-framework-petclinic](https://github.com/spring-petclinic/spring-framework-petclinic) but with Java Configuration instead of XML | -| [spring-petclinic-angular1](https://github.com/spring-petclinic/spring-petclinic-angular1) | AngularJS 1.x, Spring Boot and Spring Data JPA | +| [spring-petclinic-angular](https://github.com/spring-petclinic/spring-petclinic-angularjs) | AngularJS 1.x, Spring Boot and Spring Data JPA | | [spring-petclinic-microservices](https://github.com/spring-petclinic/spring-petclinic-microservices) | Distributed version of Spring Petclinic built with Spring Cloud | | [spring-petclinic-reactjs](https://github.com/spring-petclinic/spring-petclinic-reactjs) | ReactJS (with TypeScript) and Spring Boot | From 101c9dc69064633f697d93dcf0918bb4f74ff7ed Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 30 Jun 2017 11:07:07 +0100 Subject: [PATCH 14/30] Update Spring Boot and Thymeleaf versions --- pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index ff677d097..f64e6d122 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.1.RELEASE + 1.5.4.RELEASE petclinic @@ -26,8 +26,7 @@ 1.11.4 2.2.4 1.8.0 - - 3.0.2.RELEASE + 3.0.6.RELEASE 2.7 From cdbfafe0775079485edf50f5702ba300258239d1 Mon Sep 17 00:00:00 2001 From: Jeric Bryle Sy Dy Date: Fri, 9 Jun 2017 12:01:37 +0800 Subject: [PATCH 15/30] set pet to owner to avoid null owner when user gets an error on new pet page --- .../springframework/samples/petclinic/owner/PetController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0599faf2c..45b87c6b1 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java @@ -83,11 +83,11 @@ class PetController { 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 { - owner.addPet(pet); this.pets.save(pet); return "redirect:/owners/{ownerId}"; } From 162d8d8e45613610b6b28e78ed94c44054c2914e Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Thu, 24 Aug 2017 18:26:45 +0200 Subject: [PATCH 16/30] Add Apache 2.0 license #260 --- pom.xml | 12 ++++++++++-- readme.md | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index f64e6d122..6fdc4d17e 100644 --- a/pom.xml +++ b/pom.xml @@ -124,7 +124,7 @@ spring-boot-maven-plugin - build-info @@ -157,7 +157,7 @@ - pl.project13.maven @@ -225,4 +225,12 @@ + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0 + + + diff --git a/readme.md b/readme.md index ac30d6392..c43ef63f9 100644 --- a/readme.md +++ b/readme.md @@ -100,6 +100,6 @@ The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at . +# License - - +The Spring PetClinic sample application is released under version 2.0 of the [Apache License](http://www.apache.org/licenses/LICENSE-2.0). From fa3b7f9a4c6a4b2cab8f2492bf1ef187fdd8e619 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 3 Nov 2017 11:18:15 +0000 Subject: [PATCH 17/30] Add CLA link to readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index c43ef63f9..34161874a 100644 --- a/readme.md +++ b/readme.md @@ -98,7 +98,7 @@ Here is a list of them: The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, features requests and submitting pull requests. -For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at . +For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at . If you have not previously done so, please fill out and submit the https://cla.pivotal.io/sign/spring[Contributor License Agreement]. # License From 05e891cec11e7afa6d2d7230113ffcf5a948815b Mon Sep 17 00:00:00 2001 From: Aditya Ketkar Date: Sun, 29 Oct 2017 19:02:39 +0530 Subject: [PATCH 18/30] Removed redundant javadoc comments --- .../samples/petclinic/visit/Visit.java | 45 +++---------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java index 25e7cc5ad..251d027df 100755 --- a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java +++ b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java @@ -37,24 +37,16 @@ import org.springframework.samples.petclinic.model.BaseEntity; @Table(name = "visits") public class Visit extends BaseEntity { - /** - * Holds value of property date. - */ @Column(name = "visit_date") @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(pattern = "yyyy/MM/dd") private Date date; - /** - * Holds value of property description. - */ @NotEmpty @Column(name = "description") private String description; - /** - * Holds value of property pet. - */ + @Column(name = "pet_id") private Integer petId; @@ -67,56 +59,31 @@ public class Visit extends BaseEntity { } - /** - * Getter for property date. - * - * @return Value of property date. - */ public Date getDate() { return this.date; } - /** - * Setter for property date. - * - * @param date New value of property date. - */ + public void setDate(Date date) { this.date = date; } - /** - * Getter for property description. - * - * @return Value of property description. - */ + public String getDescription() { return this.description; } - /** - * Setter for property description. - * - * @param description New value of property description. - */ + public void setDescription(String description) { this.description = description; } - /** - * Getter for property pet id. - * - * @return Value of property pet id. - */ + public Integer getPetId() { return this.petId; } - /** - * Setter for property pet id. - * - * @param petId New value of property pet id. - */ + public void setPetId(Integer petId) { this.petId = petId; } From 4b3d6abfed2054ba54d3b044dcb993b7e1d6b92e Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Sat, 2 Sep 2017 11:17:02 +0200 Subject: [PATCH 19/30] Reference new forks: spring-petclinic-kotlin, spring-petclinic-graphql and spring-petclinic-rest --- readme.md | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index 34161874a..3f4c376ec 100644 --- a/readme.md +++ b/readme.md @@ -73,13 +73,17 @@ 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. -| Link | Main technologies | -|----------------|-------------------| -| [spring-framework-petclinic](https://github.com/spring-petclinic/spring-framework-petclinic) | Spring Framework XML configuration, JSP pages, 3 persistence layers: JDBC, JPA and Spring Data JPA | -| [javaconfig branch](https://github.com/spring-petclinic/spring-framework-petclinic/tree/javaconfig) | Same frameworks as the [spring-framework-petclinic](https://github.com/spring-petclinic/spring-framework-petclinic) but with Java Configuration instead of XML | -| [spring-petclinic-angular](https://github.com/spring-petclinic/spring-petclinic-angularjs) | AngularJS 1.x, Spring Boot and Spring Data JPA | -| [spring-petclinic-microservices](https://github.com/spring-petclinic/spring-petclinic-microservices) | Distributed version of Spring Petclinic built with Spring Cloud | -| [spring-petclinic-reactjs](https://github.com/spring-petclinic/spring-petclinic-reactjs) | ReactJS (with TypeScript) and Spring Boot | +| Link | Main technologies | +|------------------------------------|-------------------| +| [spring-framework-petclinic][] | Spring Framework XML configuration, JSP pages, 3 persistence layers: JDBC, JPA and Spring Data JPA | +| [javaconfig branch][] | Same frameworks as the [spring-framework-petclinic][] but with Java Configuration instead of XML | +| [spring-petclinic-angularjs][] | AngularJS 1.x, Spring Boot and Spring Data JPA | +| [spring-petclinic-angular][] | Angular 4 front-end of the Petclinic REST API [spring-petclinic-rest][] | +| [spring-petclinic-microservices][] | Distributed version of Spring Petclinic built with Spring Cloud | +| [spring-petclinic-reactjs][] | ReactJS (with TypeScript) and Spring Boot | +| [spring-petclinic-graphql][] | GraphQL version based on React Appolo, TypeScript and GraphQL Spring boot starter | +| [spring-petclinic-kotlin][] | Kotlin version of [spring-petclinic][] | +| [spring-petclinic-rest][] | Backend REST API | ## Interaction with other open source projects @@ -103,3 +107,13 @@ For pull requests, editor preferences are available in the [editor config](.edit # License The Spring PetClinic sample application is released under version 2.0 of the [Apache License](http://www.apache.org/licenses/LICENSE-2.0). + +[spring-petclinic]: https://github.com/spring-projects/spring-petclinic +[spring-framework-petclinic]: https://github.com/spring-petclinic/spring-framework-petclinic +[spring-petclinic-angularjs]: https://github.com/spring-petclinic/spring-petclinic-angularjs +[javaconfig branch]: https://github.com/spring-petclinic/spring-framework-petclinic/tree/javaconfig +[spring-petclinic-angular]: https://github.com/spring-petclinic/spring-petclinic-angular +[spring-petclinic-microservices]: https://github.com/spring-petclinic/spring-petclinic-microservices +[spring-petclinic-reactjs]: https://github.com/spring-petclinic/spring-petclinic-reactjs +[spring-petclinic-graphql]: https://github.com/spring-petclinic/spring-petclinic-graphql +[spring-petclinic-kotlin]: https://github.com/spring-petclinic/spring-petclinic-kotlin From 4be8ba2c4349616e1da9d8232250e20da2daec47 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Wed, 23 Aug 2017 18:38:39 +0200 Subject: [PATCH 20/30] Replace @RequestMapping by their corresponding shortcut @GetMapping and @PostMapping --- .../petclinic/owner/OwnerController.java | 27 +++++++++---------- .../petclinic/owner/PetController.java | 21 ++++++--------- .../petclinic/owner/VisitController.java | 17 +++++------- .../petclinic/system/CrashController.java | 3 ++- .../petclinic/system/WelcomeController.java | 4 +-- .../samples/petclinic/vet/VetController.java | 10 +++---- 6 files changed, 36 insertions(+), 46 deletions(-) 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 ef3169b70..d914ed745 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java @@ -15,22 +15,21 @@ */ package org.springframework.samples.petclinic.owner; -import java.util.Collection; -import java.util.Map; - -import javax.validation.Valid; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.servlet.ModelAndView; +import javax.validation.Valid; +import java.util.Collection; +import java.util.Map; + /** * @author Juergen Hoeller * @author Ken Krebs @@ -54,14 +53,14 @@ class OwnerController { dataBinder.setDisallowedFields("id"); } - @RequestMapping(value = "/owners/new", method = RequestMethod.GET) + @GetMapping("/owners/new") public String initCreationForm(Map model) { Owner owner = new Owner(); model.put("owner", owner); return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; } - @RequestMapping(value = "/owners/new", method = RequestMethod.POST) + @PostMapping("/owners/new") public String processCreationForm(@Valid Owner owner, BindingResult result) { if (result.hasErrors()) { return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; @@ -71,13 +70,13 @@ class OwnerController { } } - @RequestMapping(value = "/owners/find", method = RequestMethod.GET) + @GetMapping("/owners/find") public String initFindForm(Map model) { model.put("owner", new Owner()); return "owners/findOwners"; } - @RequestMapping(value = "/owners", method = RequestMethod.GET) + @GetMapping("/owners") public String processFindForm(Owner owner, BindingResult result, Map model) { // allow parameterless GET request for /owners to return all records @@ -102,14 +101,14 @@ class OwnerController { } } - @RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.GET) + @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; } - @RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.POST) + @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; @@ -126,7 +125,7 @@ class OwnerController { * @param ownerId the ID of the owner to display * @return a ModelMap with the model attributes for the view */ - @RequestMapping("/owners/{ownerId}") + @GetMapping("/owners/{ownerId}") public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { ModelAndView mav = new ModelAndView("owners/ownerDetails"); mav.addObject(this.owners.findById(ownerId)); 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 45b87c6b1..9c52e0309 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java @@ -15,21 +15,16 @@ */ package org.springframework.samples.petclinic.owner; -import java.util.Collection; - -import javax.validation.Valid; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.util.StringUtils; import org.springframework.validation.BindingResult; import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.annotation.InitBinder; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.Collection; /** * @author Juergen Hoeller @@ -70,7 +65,7 @@ class PetController { dataBinder.setValidator(new PetValidator()); } - @RequestMapping(value = "/pets/new", method = RequestMethod.GET) + @GetMapping("/pets/new") public String initCreationForm(Owner owner, ModelMap model) { Pet pet = new Pet(); owner.addPet(pet); @@ -78,7 +73,7 @@ class PetController { return VIEWS_PETS_CREATE_OR_UPDATE_FORM; } - @RequestMapping(value = "/pets/new", method = RequestMethod.POST) + @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"); @@ -93,14 +88,14 @@ class PetController { } } - @RequestMapping(value = "/pets/{petId}/edit", method = RequestMethod.GET) + @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; } - @RequestMapping(value = "/pets/{petId}/edit", method = RequestMethod.POST) + @PostMapping("/pets/{petId}/edit") public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owner, ModelMap model) { if (result.hasErrors()) { pet.setOwner(owner); 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 d98c5dd0f..d7afed12e 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java @@ -15,21 +15,16 @@ */ package org.springframework.samples.petclinic.owner; -import java.util.Map; - -import javax.validation.Valid; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.samples.petclinic.visit.Visit; import org.springframework.samples.petclinic.visit.VisitRepository; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.annotation.InitBinder; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.Map; /** * @author Juergen Hoeller @@ -76,13 +71,13 @@ class VisitController { } // Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called - @RequestMapping(value = "/owners/*/pets/{petId}/visits/new", method = RequestMethod.GET) + @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 - @RequestMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST) + @PostMapping("/owners/{ownerId}/pets/{petId}/visits/new") public String processNewVisitForm(@Valid Visit visit, BindingResult result) { if (result.hasErrors()) { return "pets/createOrUpdateVisitForm"; diff --git a/src/main/java/org/springframework/samples/petclinic/system/CrashController.java b/src/main/java/org/springframework/samples/petclinic/system/CrashController.java index a702cfc8f..c18c04dd8 100644 --- a/src/main/java/org/springframework/samples/petclinic/system/CrashController.java +++ b/src/main/java/org/springframework/samples/petclinic/system/CrashController.java @@ -16,6 +16,7 @@ package org.springframework.samples.petclinic.system; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -29,7 +30,7 @@ import org.springframework.web.bind.annotation.RequestMethod; @Controller class CrashController { - @RequestMapping(value = "/oups", method = RequestMethod.GET) + @GetMapping("/oups") public String triggerException() { throw new RuntimeException( "Expected: controller used to showcase what " + "happens when an exception is thrown"); diff --git a/src/main/java/org/springframework/samples/petclinic/system/WelcomeController.java b/src/main/java/org/springframework/samples/petclinic/system/WelcomeController.java index b5af0f7d7..00430a790 100644 --- a/src/main/java/org/springframework/samples/petclinic/system/WelcomeController.java +++ b/src/main/java/org/springframework/samples/petclinic/system/WelcomeController.java @@ -2,12 +2,12 @@ package org.springframework.samples.petclinic.system; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; @Controller class WelcomeController { - @RequestMapping("/") + @GetMapping("/") public String welcome() { return "welcome"; } diff --git a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java index 8ddcca60a..7ce8374ec 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java @@ -15,13 +15,13 @@ */ package org.springframework.samples.petclinic.vet; -import java.util.Map; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; +import java.util.Map; + /** * @author Juergen Hoeller * @author Mark Fisher @@ -38,7 +38,7 @@ class VetController { this.vets = clinicService; } - @RequestMapping(value = { "/vets.html" }) + @GetMapping("/vets.html") public String showVetList(Map model) { // Here we are returning an object of type 'Vets' rather than a collection of Vet // objects so it is simpler for Object-Xml mapping @@ -48,7 +48,7 @@ class VetController { return "vets/vetList"; } - @RequestMapping(value = { "/vets.json", "/vets.xml" }) + @GetMapping({ "/vets.json", "/vets.xml" }) public @ResponseBody Vets showResourcesVetList() { // Here we are returning an object of type 'Vets' rather than a collection of Vet // objects so it is simpler for JSon/Object mapping From 4ab6a800c84657b8c8fad5611f7ba2ebf87ee219 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Wed, 23 Aug 2017 18:17:57 +0200 Subject: [PATCH 21/30] Removing .springBeans --- .springBeans | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .springBeans diff --git a/.springBeans b/.springBeans deleted file mode 100644 index 44f18becd..000000000 --- a/.springBeans +++ /dev/null @@ -1,20 +0,0 @@ - - - 1 - - - - - - - src/main/resources/spring/datasource-config.xml - src/main/resources/spring/mvc-core-config.xml - src/main/resources/spring/mvc-view-config.xml - src/main/resources/spring/business-config.xml - - - src/main/resources/spring/tools-config.xml - - - - From 3e65dee2371d4517fa29d6de44d2a77f0ff3065c Mon Sep 17 00:00:00 2001 From: dastier Date: Sun, 9 Jul 2017 23:45:42 +0300 Subject: [PATCH 22/30] fix button text in createOrUpdatePetForm.html in case of new pet (issue #252) --- src/main/resources/templates/pets/createOrUpdatePetForm.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/pets/createOrUpdatePetForm.html b/src/main/resources/templates/pets/createOrUpdatePetForm.html index bfa07d1ff..e4726e155 100644 --- a/src/main/resources/templates/pets/createOrUpdatePetForm.html +++ b/src/main/resources/templates/pets/createOrUpdatePetForm.html @@ -26,7 +26,7 @@
From 5b0f037d06de2c9ad3be4fdf52402ddb5667e2da Mon Sep 17 00:00:00 2001 From: thetric Date: Fri, 19 May 2017 12:16:02 +0200 Subject: [PATCH 23/30] fix: make id 'lastName' in findOwners.html unique previously the div.control-group and the containing input shared the same id --- src/main/resources/templates/owners/findOwners.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/owners/findOwners.html b/src/main/resources/templates/owners/findOwners.html index 911ac9581..982be5e81 100644 --- a/src/main/resources/templates/owners/findOwners.html +++ b/src/main/resources/templates/owners/findOwners.html @@ -8,7 +8,7 @@
-
+
Date: Mon, 5 Dec 2016 21:32:44 +0100 Subject: [PATCH 24/30] Fix date formatting --- .../java/org/springframework/samples/petclinic/owner/Pet.java | 2 +- .../java/org/springframework/samples/petclinic/visit/Visit.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/main/java/org/springframework/samples/petclinic/owner/Pet.java diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java old mode 100644 new mode 100755 index e8df85e91..5e226a180 --- a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java @@ -53,7 +53,7 @@ public class Pet extends NamedEntity { @Column(name = "birth_date") @Temporal(TemporalType.DATE) - @DateTimeFormat(pattern = "yyyy/MM/dd") + @DateTimeFormat(pattern = "yyyy-MM-dd") private Date birthDate; @ManyToOne diff --git a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java index 251d027df..f83d1463c 100755 --- a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java +++ b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java @@ -39,7 +39,7 @@ public class Visit extends BaseEntity { @Column(name = "visit_date") @Temporal(TemporalType.TIMESTAMP) - @DateTimeFormat(pattern = "yyyy/MM/dd") + @DateTimeFormat(pattern = "yyyy-MM-dd") private Date date; @NotEmpty From 23f65ba7d0101adeb32f36fd8f634549ee3d6e40 Mon Sep 17 00:00:00 2001 From: Oscar Utbult Date: Mon, 5 Dec 2016 22:18:58 +0100 Subject: [PATCH 25/30] Fix broken tests --- .../samples/petclinic/owner/PetControllerTests.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java old mode 100644 new mode 100755 index f56931cb6..64876906c --- a/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java @@ -75,7 +75,7 @@ public class PetControllerTests { mockMvc.perform(post("/owners/{ownerId}/pets/new", TEST_OWNER_ID) .param("name", "Betty") .param("type", "hamster") - .param("birthDate", "2015/02/12") + .param("birthDate", "2015-02-12") ) .andExpect(status().is3xxRedirection()) .andExpect(view().name("redirect:/owners/{ownerId}")); @@ -85,7 +85,7 @@ public class PetControllerTests { public void testProcessCreationFormHasErrors() throws Exception { mockMvc.perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID) .param("name", "Betty") - .param("birthDate", "2015/02/12") + .param("birthDate", "2015-02-12") ) .andExpect(model().attributeHasNoErrors("owner")) .andExpect(model().attributeHasErrors("pet")) @@ -106,7 +106,7 @@ public class PetControllerTests { mockMvc.perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID) .param("name", "Betty") .param("type", "hamster") - .param("birthDate", "2015/02/12") + .param("birthDate", "2015-02-12") ) .andExpect(status().is3xxRedirection()) .andExpect(view().name("redirect:/owners/{ownerId}")); From e20b43b0090bc7a13de4b177ff02c3900f168a05 Mon Sep 17 00:00:00 2001 From: sunflower2014 Date: Sun, 15 Oct 2017 16:08:44 +0800 Subject: [PATCH 26/30] Update PetControllerTests.java correct testProcessCreationFormHasErrors method's post url --- .../samples/petclinic/owner/PetControllerTests.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java index 64876906c..f95d7c87c 100755 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java @@ -83,12 +83,14 @@ public class PetControllerTests { @Test public void testProcessCreationFormHasErrors() throws Exception { - mockMvc.perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID) + mockMvc.perform(post("/owners/{ownerId}/pets/new", TEST_OWNER_ID) .param("name", "Betty") .param("birthDate", "2015-02-12") ) .andExpect(model().attributeHasNoErrors("owner")) .andExpect(model().attributeHasErrors("pet")) + .andExpect(model().attributeHasFieldErrors("pet", "type")) + .andExpect(model().attributeHasFieldErrorCode("pet", "type", "required")) .andExpect(status().isOk()) .andExpect(view().name("pets/createOrUpdatePetForm")); } From c36452a2c34443ae26b4ecbba4f149906af14717 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 3 Nov 2017 14:17:04 +0000 Subject: [PATCH 27/30] Use leading / in app URL Fixes gh-267 --- src/main/resources/templates/owners/ownersList.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/owners/ownersList.html b/src/main/resources/templates/owners/ownersList.html index dc4c44635..478b37e5d 100644 --- a/src/main/resources/templates/owners/ownersList.html +++ b/src/main/resources/templates/owners/ownersList.html @@ -19,7 +19,7 @@ - + From 14ef611d7008248b181282c441a1769ba955047e Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 9 Jan 2018 17:50:14 +0000 Subject: [PATCH 28/30] Update to Spring Boot 2.0 snapshots --- pom.xml | 9 +-------- src/main/resources/application.properties | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 6fdc4d17e..6e1d8e682 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.4.RELEASE + 2.0.0.BUILD-SNAPSHOT petclinic @@ -26,7 +26,6 @@ 1.11.4 2.2.4 1.8.0 - 3.0.6.RELEASE 2.7 @@ -53,12 +52,6 @@ org.springframework.boot spring-boot-starter-thymeleaf - - - nz.net.ultraq.thymeleaf - thymeleaf-layout-dialect - - org.springframework.boot diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index fb07c6c50..ed5392afe 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -13,9 +13,9 @@ spring.jpa.hibernate.ddl-auto=none spring.messages.basename=messages/messages # Actuator / Management -management.contextPath=/manage +management.endpoints.web.base-path=/manage # Spring Boot 1.5 makes actuator secure by default -management.security.enabled=false +management.endpoints.web.enabled=true # Logging logging.level.org.springframework=INFO From cf352663366ecabc4ed9aad125e7373e040bca45 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 11 Jan 2018 09:15:18 +0000 Subject: [PATCH 29/30] Tidy up compiler warnings --- .../samples/petclinic/model/Person.java | 3 +-- .../samples/petclinic/owner/Owner.java | 18 +++++++----------- .../petclinic/system/CrashController.java | 6 ++---- .../samples/petclinic/visit/Visit.java | 10 +--------- .../petclinic/model/ValidatorTests.java | 15 ++++++++------- .../petclinic/owner/PetTypeFormatterTests.java | 13 +++++-------- 6 files changed, 24 insertions(+), 41 deletions(-) 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 4cb7481e0..5d23523bd 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Person.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Person.java @@ -17,8 +17,7 @@ package org.springframework.samples.petclinic.model; import javax.persistence.Column; import javax.persistence.MappedSuperclass; - -import org.hibernate.validator.constraints.NotEmpty; +import javax.validation.constraints.NotEmpty; /** * Simple JavaBean domain object representing an person. 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 f6fcae7ac..89aad2c2c 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java @@ -27,8 +27,8 @@ import javax.persistence.Entity; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.validation.constraints.Digits; +import javax.validation.constraints.NotEmpty; -import org.hibernate.validator.constraints.NotEmpty; import org.springframework.beans.support.MutableSortDefinition; import org.springframework.beans.support.PropertyComparator; import org.springframework.core.style.ToStringCreator; @@ -61,7 +61,6 @@ public class Owner extends Person { @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") private Set pets; - public String getAddress() { return this.address; } @@ -99,7 +98,8 @@ public class Owner extends Person { public List getPets() { List sortedPets = new ArrayList<>(getPetsInternal()); - PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true)); + PropertyComparator.sort(sortedPets, + new MutableSortDefinition("name", true, true)); return Collections.unmodifiableList(sortedPets); } @@ -144,13 +144,9 @@ public class Owner extends Person { 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(); + .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/system/CrashController.java b/src/main/java/org/springframework/samples/petclinic/system/CrashController.java index c18c04dd8..2f5e7a348 100644 --- a/src/main/java/org/springframework/samples/petclinic/system/CrashController.java +++ b/src/main/java/org/springframework/samples/petclinic/system/CrashController.java @@ -17,8 +17,6 @@ package org.springframework.samples.petclinic.system; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; /** * Controller used to showcase what happens when an exception is thrown @@ -32,8 +30,8 @@ class CrashController { @GetMapping("/oups") public String triggerException() { - throw new RuntimeException( - "Expected: controller used to showcase what " + "happens when an exception is thrown"); + throw new RuntimeException("Expected: controller used to showcase what " + + "happens when an exception is thrown"); } } diff --git a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java index f83d1463c..ce10d7b12 100755 --- a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java +++ b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java @@ -22,8 +22,8 @@ import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.validation.constraints.NotEmpty; -import org.hibernate.validator.constraints.NotEmpty; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.samples.petclinic.model.BaseEntity; @@ -46,11 +46,9 @@ public class Visit extends BaseEntity { @Column(name = "description") private String description; - @Column(name = "pet_id") private Integer petId; - /** * Creates a new instance of Visit for the current date */ @@ -58,32 +56,26 @@ public class Visit extends BaseEntity { this.date = new Date(); } - public Date getDate() { return this.date; } - public void setDate(Date date) { this.date = date; } - public String getDescription() { return this.description; } - public void setDescription(String description) { this.description = description; } - public Integer getPetId() { return this.petId; } - public void setPetId(Integer petId) { this.petId = petId; } diff --git a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java index b836d0cc2..7da0d3dea 100644 --- a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java +++ b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java @@ -1,7 +1,5 @@ package org.springframework.samples.petclinic.model; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Locale; import java.util.Set; @@ -9,13 +7,15 @@ import javax.validation.ConstraintViolation; import javax.validation.Validator; import org.junit.Test; + import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; +import static org.assertj.core.api.Assertions.assertThat; + /** - * @author Michael Isvy - * Simple test to make sure that Bean Validation is working - * (useful when upgrading to a new version of Hibernate Validator/ Bean Validation) + * @author Michael Isvy Simple test to make sure that Bean Validation is working (useful + * when upgrading to a new version of Hibernate Validator/ Bean Validation) */ public class ValidatorTests { @@ -34,12 +34,13 @@ public class ValidatorTests { person.setLastName("smith"); Validator validator = createValidator(); - Set> constraintViolations = validator.validate(person); + Set> constraintViolations = validator + .validate(person); assertThat(constraintViolations.size()).isEqualTo(1); ConstraintViolation violation = constraintViolations.iterator().next(); assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName"); - assertThat(violation.getMessage()).isEqualTo("may not be empty"); + assertThat(violation.getMessage()).isEqualTo("must not be empty"); } } diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java index f332257bc..4e8e36c14 100644 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java @@ -1,7 +1,5 @@ package org.springframework.samples.petclinic.owner; -import static org.junit.Assert.assertEquals; - import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; @@ -13,10 +11,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.samples.petclinic.owner.PetRepository; -import org.springframework.samples.petclinic.owner.PetType; -import org.springframework.samples.petclinic.owner.PetTypeFormatter; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.junit.Assert.assertEquals; /** * Test class for {@link PetTypeFormatter} @@ -64,12 +61,12 @@ public class PetTypeFormatterTests { */ private List makePetTypes() { List petTypes = new ArrayList<>(); - petTypes.add(new PetType(){ + petTypes.add(new PetType() { { setName("Dog"); } }); - petTypes.add(new PetType(){ + petTypes.add(new PetType() { { setName("Bird"); } From c91b73e75e5e2d9dc13fa2646757834a50ac07ca Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 11 Jan 2018 09:16:04 +0000 Subject: [PATCH 30/30] Update version of Petclinic --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6e1d8e682..fa5e4df94 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.springframework.samples spring-petclinic - 1.5.1 + 2.0.0 org.springframework.boot