Skip to content

Commit ff7668c

Browse files
Upgrade dependencies & polish code (#21)
- Spring Boot 3.4.4 - MySQL 9.2
1 parent 8ed306c commit ff7668c

File tree

10 files changed

+25
-34
lines changed

10 files changed

+25
-34
lines changed

docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
version: "2.2"
2-
31
services:
42
mysql:
5-
image: mysql:8.0
3+
image: mysql:9.2
64
ports:
75
- "3306:3306"
86
environment:

pom.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<parent>
1111
<groupId>org.springframework.boot</groupId>
1212
<artifactId>spring-boot-starter-parent</artifactId>
13-
<version>3.0.5</version>
13+
<version>3.4.4</version>
1414
</parent>
1515
<name>petclinic</name>
1616

@@ -64,7 +64,6 @@
6464
<dependency>
6565
<groupId>org.testcontainers</groupId>
6666
<artifactId>mysql</artifactId>
67-
<version>1.17.6</version>
6867
<scope>test</scope>
6968
</dependency>
7069

@@ -138,8 +137,7 @@
138137
<additionalProperties>
139138
<encoding.source>${project.build.sourceEncoding}</encoding.source>
140139
<encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
141-
<java.source>${maven.compiler.source}</java.source>
142-
<java.target>${maven.compiler.target}</java.target>
140+
<java.version>${maven.compiler.release}</java.version>
143141
</additionalProperties>
144142
</configuration>
145143
</execution>

src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
141141
return mav;
142142
}
143143

144-
static record OwnerDetails(Owner owner, List<Pet> pets) {
144+
record OwnerDetails(Owner owner, List<Pet> pets) {
145145
}
146146

147-
static record PetDetails(Pet pet, PetType type, List<Visit> visits) {
147+
record PetDetails(Pet pet, PetType type, List<Visit> visits) {
148148
}
149149

150150
}

src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Repository class for <code>Owner</code> domain objects All method names are compliant with Spring Data naming
2626
* conventions so this interface can easily be extended for Spring Data See here:
27-
* http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
27+
* <a href="https://docs.spring.io/spring-data/jpa/reference/repositories/query-methods-details.html#repositories.query-methods.query-creation">Query Creation</a>
2828
*
2929
* @author Ken Krebs
3030
* @author Juergen Hoeller
@@ -37,7 +37,7 @@ public interface OwnerRepository extends Repository<Owner, Integer> {
3737
/**
3838
* Retrieve {@link Owner}s from the data store by last name, returning all owners whose last name <i>starts</i> with
3939
* the given name.
40-
*
40+
*
4141
* @param lastName Value to search for
4242
* @return a Collection of matching {@link Owner}s (or an empty Collection if none found)
4343
*/
@@ -47,7 +47,7 @@ public interface OwnerRepository extends Repository<Owner, Integer> {
4747

4848
/**
4949
* Retrieve an {@link Owner} from the data store by id.
50-
*
50+
*
5151
* @param id the id to search for
5252
* @return the {@link Owner} if found
5353
*/
@@ -56,7 +56,7 @@ public interface OwnerRepository extends Repository<Owner, Integer> {
5656

5757
/**
5858
* Save an {@link Owner} to the data store, either inserting or updating it.
59-
*
59+
*
6060
* @param owner the {@link Owner} to save
6161
*/
6262
void save(Owner owner);

src/main/java/org/springframework/samples/petclinic/owner/PetRepository.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Repository class for <code>Pet</code> domain objects All method names are compliant with Spring Data naming
2626
* conventions so this interface can easily be extended for Spring Data See here:
27-
* http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
27+
* <a href="https://docs.spring.io/spring-data/jpa/reference/repositories/query-methods-details.html#repositories.query-methods.query-creation">Query Creation</a>
2828
*
2929
* @author Ken Krebs
3030
* @author Juergen Hoeller
@@ -36,7 +36,7 @@ public interface PetRepository extends Repository<Pet, Integer> {
3636

3737
/**
3838
* Retrieve all {@link PetType}s from the data store.
39-
*
39+
*
4040
* @return a Collection of {@link PetType}s.
4141
*/
4242
@Query("select * from pet_type order by name")
@@ -48,7 +48,7 @@ public interface PetRepository extends Repository<Pet, Integer> {
4848

4949
/**
5050
* Retrieve a {@link Pet} from the data store by id.
51-
*
51+
*
5252
* @param id the id to search for
5353
* @return the {@link Pet} if found
5454
*/
@@ -57,7 +57,7 @@ public interface PetRepository extends Repository<Pet, Integer> {
5757

5858
/**
5959
* Save a {@link Pet} to the data store, either inserting or updating it.
60-
*
60+
*
6161
* @param pet the {@link Pet} to save
6262
*/
6363
void save(Pet pet);

src/main/java/org/springframework/samples/petclinic/owner/PetTypeFormatter.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@
1818
import java.text.ParseException;
1919
import java.util.Collection;
2020
import java.util.Locale;
21-
import org.springframework.beans.factory.annotation.Autowired;
21+
import java.util.stream.Collectors;
22+
2223
import org.springframework.format.Formatter;
2324
import org.springframework.stereotype.Component;
2425

2526
/**
2627
* Instructs Spring MVC on how to parse and print elements of type 'PetType'. Starting from Spring 3.0, Formatters have
2728
* come as an improvement in comparison to legacy PropertyEditors. See the following links for more details: - The
2829
* Spring ref doc:
29-
* http://static.springsource.org/spring/docs/current/spring-framework-reference/html/validation.html#format-Formatter-SPI
30-
* - A nice blog entry from Gordon Dickens:
31-
* http://gordondickens.com/wordpress/2010/09/30/using-spring-3-0-custom-type-converter/
32-
* <p/>
30+
* <a href="https://docs.spring.io/spring-framework/reference/core/validation/format.html#format-Formatter-SPI">Formatter SPI</a>
3331
*
3432
* @author Mark Fisher
3533
* @author Juergen Hoeller
@@ -40,7 +38,6 @@ public class PetTypeFormatter implements Formatter<PetType> {
4038

4139
private final PetRepository pets;
4240

43-
@Autowired
4441
public PetTypeFormatter(PetRepository pets) {
4542
this.pets = pets;
4643
}
@@ -52,13 +49,11 @@ public String print(PetType petType, Locale locale) {
5249

5350
@Override
5451
public PetType parse(String text, Locale locale) throws ParseException {
55-
Collection<PetType> findPetTypes = this.pets.findPetTypes();
56-
for (PetType type : findPetTypes) {
57-
if (type.name().equals(text)) {
58-
return type;
59-
}
60-
}
61-
throw new ParseException("type not found: " + text, 0);
52+
return this.pets.findPetTypes()
53+
.stream()
54+
.filter(t -> t.name().equals(text))
55+
.findFirst()
56+
.orElseThrow(() -> new ParseException("type not found: " + text, 0));
6257
}
6358

6459
}

src/main/java/org/springframework/samples/petclinic/owner/VisitController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void setAllowedFields(WebDataBinder dataBinder) {
5959
* Since we do not use the session scope, make sure that Pet object always has an id (Even though id is not part of
6060
* the form fields)
6161
*
62-
* @param petId
62+
* @param petId - pet id
6363
* @return Pet
6464
*/
6565
@ModelAttribute("visit")

src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/**
2727
* Repository class for <code>Vet</code> domain objects All method names are compliant with Spring Data naming
2828
* conventions so this interface can easily be extended for Spring Data See here:
29-
* http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
29+
* <a href="https://docs.spring.io/spring-data/jpa/reference/repositories/query-methods-details.html#repositories.query-methods.query-creation">Query Creation</a>
3030
*
3131
* @author Ken Krebs
3232
* @author Juergen Hoeller

src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Repository class for <code>Visit</code> domain objects All method names are compliant with Spring Data naming
2626
* conventions so this interface can easily be extended for Spring Data See here:
27-
* http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
27+
* <a href="https://docs.spring.io/spring-data/jpa/reference/repositories/query-methods-details.html#repositories.query-methods.query-creation">Query Creation</a>
2828
*
2929
* @author Ken Krebs
3030
* @author Juergen Hoeller
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# use test containers to spin up mysql
2-
spring.datasource.url=jdbc:tc:mysql:8.0.25://hostname/databasename
2+
spring.datasource.url=jdbc:tc:mysql:9.2://hostname/databasename

0 commit comments

Comments
 (0)