Skip to content

Commit 55cbdd5

Browse files
committed
Upgrade the samples to Spring Boot 2.4.x
Closes gh-723
1 parent bf1bfc4 commit 55cbdd5

27 files changed

+255
-309
lines changed

samples/junit5/build.gradle

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
buildscript {
2-
repositories {
3-
mavenCentral()
4-
}
5-
dependencies {
6-
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.9.RELEASE'
7-
}
8-
}
9-
101
plugins {
2+
id "eclipse"
3+
id "java"
114
id "org.asciidoctor.jvm.convert" version "3.3.2"
5+
id "org.springframework.boot" version "2.4.7"
126
}
137

14-
apply plugin: 'java'
15-
apply plugin: 'org.springframework.boot'
16-
apply plugin: 'eclipse'
178
apply plugin: 'io.spring.dependency-management'
189

1910
repositories {

samples/rest-assured/build.gradle

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
buildscript {
2-
repositories {
3-
mavenCentral()
4-
}
5-
dependencies {
6-
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.9.RELEASE'
7-
}
8-
}
9-
101
plugins {
2+
id "eclipse"
3+
id "java"
114
id "org.asciidoctor.jvm.convert" version "3.3.2"
5+
id "org.springframework.boot" version "2.4.7"
126
}
137

14-
apply plugin: 'java'
15-
apply plugin: 'org.springframework.boot'
16-
apply plugin: 'eclipse'
178
apply plugin: 'io.spring.dependency-management'
189

1910
repositories {
@@ -44,6 +35,9 @@ dependencies {
4435
implementation 'org.springframework.boot:spring-boot-starter-web'
4536

4637
testImplementation 'io.rest-assured:rest-assured:3.0.2'
38+
testImplementation('org.junit.vintage:junit-vintage-engine') {
39+
exclude group: 'org.hamcrest', module: 'hamcrest-core'
40+
}
4741
testImplementation 'org.springframework.boot:spring-boot-starter-test'
4842
testImplementation 'org.springframework.restdocs:spring-restdocs-restassured'
4943
}

samples/rest-notes-slate/build.gradle

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
buildscript {
2-
repositories {
3-
mavenCentral()
4-
}
5-
dependencies {
6-
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.9.RELEASE'
7-
}
1+
plugins {
2+
id "eclipse"
3+
id "java"
4+
id "org.springframework.boot" version "2.4.7"
85
}
96

10-
apply plugin: 'java'
11-
apply plugin: 'org.springframework.boot'
12-
apply plugin: 'eclipse'
137
apply plugin: 'io.spring.dependency-management'
148

159
repositories {
@@ -38,6 +32,9 @@ dependencies {
3832
runtimeOnly 'org.atteo:evo-inflector:1.2.1'
3933

4034
testImplementation 'com.jayway.jsonpath:json-path'
35+
testImplementation('org.junit.vintage:junit-vintage-engine') {
36+
exclude group: 'org.hamcrest', module: 'hamcrest-core'
37+
}
4138
testImplementation 'org.springframework.boot:spring-boot-starter-test'
4239
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
4340
}

samples/rest-notes-spring-data-rest/pom.xml

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<parent>
1212
<groupId>org.springframework.boot</groupId>
1313
<artifactId>spring-boot-starter-parent</artifactId>
14-
<version>2.1.9.RELEASE</version>
14+
<version>2.4.7</version>
1515
<relativePath />
1616
</parent>
1717

@@ -37,6 +37,17 @@
3737
<scope>runtime</scope>
3838
</dependency>
3939

40+
<dependency>
41+
<groupId>org.junit.vintage</groupId>
42+
<artifactId>junit-vintage-engine</artifactId>
43+
<scope>test</scope>
44+
<exclusions>
45+
<exclusion>
46+
<groupId>org.hamcrest</groupId>
47+
<artifactId>hamcrest-core</artifactId>
48+
</exclusion>
49+
</exclusions>
50+
</dependency>
4051
<dependency>
4152
<groupId>org.springframework.boot</groupId>
4253
<artifactId>spring-boot-starter-test</artifactId>

samples/rest-notes-spring-hateoas/build.gradle

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
buildscript {
2-
repositories {
3-
mavenCentral()
4-
}
5-
dependencies {
6-
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.9.RELEASE'
7-
}
8-
}
9-
101
plugins {
2+
id "eclipse"
3+
id "java"
114
id "org.asciidoctor.jvm.convert" version "3.3.2"
5+
id "org.springframework.boot" version "2.4.7"
126
}
137

14-
apply plugin: 'java'
15-
apply plugin: 'org.springframework.boot'
16-
apply plugin: 'eclipse'
178
apply plugin: 'io.spring.dependency-management'
189

1910
repositories {
@@ -43,12 +34,16 @@ dependencies {
4334

4435
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
4536
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
37+
implementation 'org.springframework.boot:spring-boot-starter-validation'
4638

4739
runtimeOnly 'com.h2database:h2'
4840
runtimeOnly 'org.atteo:evo-inflector:1.2.1'
4941

5042
testImplementation 'com.jayway.jsonpath:json-path'
5143
testImplementation 'org.assertj:assertj-core'
44+
testImplementation('org.junit.vintage:junit-vintage-engine') {
45+
exclude group: 'org.hamcrest', module: 'hamcrest-core'
46+
}
5247
testImplementation 'org.springframework.boot:spring-boot-starter-test'
5348
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
5449
}

samples/rest-notes-spring-hateoas/src/main/java/com/example/notes/ExceptionSupressingErrorAttributes.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Map;
2020

21+
import org.springframework.boot.web.error.ErrorAttributeOptions;
2122
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
2223
import org.springframework.stereotype.Component;
2324
import org.springframework.web.context.request.RequestAttributes;
@@ -28,8 +29,8 @@ class ExceptionSupressingErrorAttributes extends DefaultErrorAttributes {
2829

2930
@Override
3031
public Map<String, Object> getErrorAttributes(WebRequest webRequest,
31-
boolean includeStackTrace) {
32-
Map<String, Object> errorAttributes = super.getErrorAttributes(webRequest, includeStackTrace);
32+
ErrorAttributeOptions options) {
33+
Map<String, Object> errorAttributes = super.getErrorAttributes(webRequest, options);
3334
errorAttributes.remove("exception");
3435
Object message = webRequest.getAttribute("javax.servlet.error.message", RequestAttributes.SCOPE_REQUEST);
3536
if (message != null) {

samples/rest-notes-spring-hateoas/src/main/java/com/example/notes/IndexController.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,20 +16,20 @@
1616

1717
package com.example.notes;
1818

19-
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
19+
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
2020

21-
import org.springframework.hateoas.ResourceSupport;
21+
import org.springframework.hateoas.RepresentationModel;
2222
import org.springframework.web.bind.annotation.RequestMapping;
2323
import org.springframework.web.bind.annotation.RequestMethod;
2424
import org.springframework.web.bind.annotation.RestController;
2525

2626
@RestController
2727
@RequestMapping("/")
28-
public class IndexController {
28+
class IndexController {
2929

3030
@RequestMapping(method=RequestMethod.GET)
31-
public ResourceSupport index() {
32-
ResourceSupport index = new ResourceSupport();
31+
public RepresentationModel<?> index() {
32+
RepresentationModel<?> index = new RepresentationModel<>();
3333
index.add(linkTo(NotesController.class).withRel("notes"));
3434
index.add(linkTo(TagsController.class).withRel("tags"));
3535
return index;

samples/rest-notes-spring-hateoas/src/main/java/com/example/notes/NestedContentResource.java

-36
This file was deleted.

samples/rest-notes-spring-hateoas/src/main/java/com/example/notes/Note.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,6 @@
2424
import javax.persistence.Id;
2525
import javax.persistence.ManyToMany;
2626

27-
import com.fasterxml.jackson.annotation.JsonIgnore;
28-
2927
@Entity
3028
public class Note {
3129

@@ -40,7 +38,6 @@ public class Note {
4038
@ManyToMany
4139
private List<Tag> tags;
4240

43-
@JsonIgnore
4441
public long getId() {
4542
return id;
4643
}
@@ -65,12 +62,12 @@ public void setBody(String body) {
6562
this.body = body;
6663
}
6764

68-
@JsonIgnore
6965
public List<Tag> getTags() {
7066
return tags;
7167
}
7268

7369
public void setTags(List<Tag> tags) {
7470
this.tags = tags;
7571
}
72+
7673
}

samples/rest-notes-spring-hateoas/src/main/java/com/example/notes/NoteInput.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
2525
import com.fasterxml.jackson.annotation.JsonCreator;
2626
import com.fasterxml.jackson.annotation.JsonProperty;
2727

28-
public class NoteInput {
28+
class NoteInput {
2929

3030
@NotBlank
3131
private final String title;
@@ -35,23 +35,23 @@ public class NoteInput {
3535
private final List<URI> tagUris;
3636

3737
@JsonCreator
38-
public NoteInput(@JsonProperty("title") String title,
38+
NoteInput(@JsonProperty("title") String title,
3939
@JsonProperty("body") String body, @JsonProperty("tags") List<URI> tagUris) {
4040
this.title = title;
4141
this.body = body;
4242
this.tagUris = tagUris == null ? Collections.<URI>emptyList() : tagUris;
4343
}
4444

45-
public String getTitle() {
45+
String getTitle() {
4646
return title;
4747
}
4848

49-
public String getBody() {
49+
String getBody() {
5050
return body;
5151
}
5252

5353
@JsonProperty("tags")
54-
public List<URI> getTagUris() {
54+
List<URI> getTagUris() {
5555
return this.tagUris;
5656
}
5757

samples/rest-notes-spring-hateoas/src/main/java/com/example/notes/NotePatchInput.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
2323
import com.fasterxml.jackson.annotation.JsonCreator;
2424
import com.fasterxml.jackson.annotation.JsonProperty;
2525

26-
public class NotePatchInput {
26+
class NotePatchInput {
2727

2828
@NullOrNotBlank
2929
private final String title;
@@ -33,23 +33,23 @@ public class NotePatchInput {
3333
private final List<URI> tagUris;
3434

3535
@JsonCreator
36-
public NotePatchInput(@JsonProperty("title") String title,
36+
NotePatchInput(@JsonProperty("title") String title,
3737
@JsonProperty("body") String body, @JsonProperty("tags") List<URI> tagUris) {
3838
this.title = title;
3939
this.body = body;
4040
this.tagUris = tagUris == null ? Collections.<URI>emptyList() : tagUris;
4141
}
4242

43-
public String getTitle() {
43+
String getTitle() {
4444
return title;
4545
}
4646

47-
public String getBody() {
47+
String getBody() {
4848
return body;
4949
}
5050

5151
@JsonProperty("tags")
52-
public List<URI> getTagUris() {
52+
List<URI> getTagUris() {
5353
return this.tagUris;
5454
}
5555
}

samples/rest-notes-spring-hateoas/src/main/java/com/example/notes/NoteRepository.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2015 the original author or authors.
2+
* Copyright 2014-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,9 +21,10 @@
2121

2222
import org.springframework.data.repository.CrudRepository;
2323

24-
public interface NoteRepository extends CrudRepository<Note, Long> {
24+
interface NoteRepository extends CrudRepository<Note, Long> {
2525

2626
Note findById(long id);
2727

2828
List<Note> findByTagsIn(Collection<Tag> tags);
29+
2930
}

0 commit comments

Comments
 (0)