Skip to content

Commit edaf9b8

Browse files
Upgrading Spring Boot to 2.6.10.
1 parent 530150e commit edaf9b8

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

pom.xml

+1-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.2.13.RELEASE</version>
14+
<version>2.6.10</version>
1515
</parent>
1616

1717
<properties>

src/main/java/me/stritzke/moneytracker/DocumentationRootLink.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public class DocumentationRootLink implements RepresentationModelProcessor<RepositoryLinksResource> {
1010
@Override
1111
public RepositoryLinksResource process(RepositoryLinksResource resource) {
12-
resource.add(new Link("/doc/api-guide.html").withRel("doc"));
12+
resource.add(Link.of("/doc/api-guide.html").withRel("doc"));
1313
return resource;
1414
}
1515
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package me.stritzke.moneytracker;
22

33
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
4-
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
4+
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
55
import org.springframework.stereotype.Component;
6+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
67

78
@Component
8-
public class SpringDataRestConfiguration extends RepositoryRestConfigurerAdapter {
9+
public class SpringDataRestConfiguration implements RepositoryRestConfigurer {
910
@Override
10-
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration configuration) {
11-
configuration.setBasePath("/api");
11+
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) {
12+
RepositoryRestConfigurer.super.configureRepositoryRestConfiguration(config, cors);
13+
config.setBasePath("/api");
1214
}
1315
}

src/main/java/me/stritzke/moneytracker/expenses/ExpenseEndpoint.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import lombok.RequiredArgsConstructor;
44
import org.springframework.beans.factory.annotation.Autowired;
55
import org.springframework.data.rest.webmvc.RepositoryLinksResource;
6-
import org.springframework.hateoas.*;
6+
import org.springframework.hateoas.CollectionModel;
7+
import org.springframework.hateoas.Link;
8+
import org.springframework.hateoas.RepresentationModel;
79
import org.springframework.hateoas.server.ExposesResourceFor;
810
import org.springframework.hateoas.server.RepresentationModelProcessor;
9-
import org.springframework.hateoas.server.mvc.ControllerLinkBuilder;
11+
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
1012
import org.springframework.http.HttpStatus;
1113
import org.springframework.http.ResponseEntity;
1214
import org.springframework.web.bind.annotation.*;
@@ -34,22 +36,22 @@ public RepresentationModel<Expense> getExpenseRoot() {
3436
}
3537

3638
private Link getLinkToExpenses(String rel, DateWrapper date) {
37-
return ControllerLinkBuilder.linkTo(methodOn(ExpenseEndpoint.class).getExpensesOfMonth(date.getYear(), date.getMonth())).withRel(rel);
39+
return WebMvcLinkBuilder.linkTo(methodOn(ExpenseEndpoint.class).getExpensesOfMonth(date.getYear(), date.getMonth())).withRel(rel);
3840
}
3941

4042
@RequestMapping(method = RequestMethod.POST)
4143
public ResponseEntity<?> addExpense(@RequestBody ExpenseCreationDTO expenseCreationDTO) {
4244
DateWrapper date = new DateWrapper();
4345
Expense expense = expenseService.save(expenseCreationDTO.getAmount(), expenseCreationDTO.getComment(), date.getYear(), date.getMonth());
44-
URI location = ControllerLinkBuilder.linkTo(methodOn(ExpenseEndpoint.class).getExpense(date.getYear(), date.getMonth(), expense.getNumericId())).toUri();
46+
URI location = WebMvcLinkBuilder.linkTo(methodOn(ExpenseEndpoint.class).getExpense(date.getYear(), date.getMonth(), expense.getNumericId())).toUri();
4547
return ResponseEntity.created(location).build();
4648
}
4749

4850
@RequestMapping(method = RequestMethod.GET, value = "/{year}/{month}")
4951
public ResponseEntity<CollectionModel<Expense>> getExpensesOfMonth(@PathVariable("year") Integer year, @PathVariable("month") Integer month) {
5052
Collection<Expense> byYearAndMonth = expenseService.find(new DateWrapper(year, month));
5153
byYearAndMonth.forEach(this::addSelfLink);
52-
CollectionModel<Expense> expenseResource = new CollectionModel<>(byYearAndMonth);
54+
CollectionModel<Expense> expenseResource = CollectionModel.of(byYearAndMonth);
5355
DateWrapper date = new DateWrapper(year, month);
5456
expenseResource.add(getLinkToExpenses("self", date));
5557
expenseResource.add(getLinkToExpenses("previous", date.getPreviousMonth()));
@@ -59,8 +61,8 @@ public ResponseEntity<CollectionModel<Expense>> getExpensesOfMonth(@PathVariable
5961

6062
private void addSelfLink(Expense expense) {
6163
expense.add(linkTo(methodOn(ExpenseEndpoint.class)
62-
.getExpense(expense.getYear(), expense.getMonth(), expense.getNumericId()))
63-
.withSelfRel());
64+
.getExpense(expense.getYear(), expense.getMonth(), expense.getNumericId()))
65+
.withSelfRel());
6466
}
6567

6668
@RequestMapping(method = RequestMethod.POST, value = "/{year}/{month}")
@@ -69,7 +71,7 @@ public ResponseEntity<?> addExpenseInMonth(@PathVariable("year") Integer year,
6971
@PathVariable("month") Integer month,
7072
@RequestBody ExpenseCreationDTO expenseCreationDTO) throws URISyntaxException {
7173
Expense expense = expenseService.save(expenseCreationDTO.getAmount(), expenseCreationDTO.getComment(), year, month);
72-
URI location = ControllerLinkBuilder.linkTo(methodOn(ExpenseEndpoint.class).getExpense(year, month, expense.getNumericId())).toUri();
74+
URI location = WebMvcLinkBuilder.linkTo(methodOn(ExpenseEndpoint.class).getExpense(year, month, expense.getNumericId())).toUri();
7375
return ResponseEntity.created(location).build();
7476
}
7577

@@ -95,7 +97,7 @@ public ResponseEntity<?> deleteExpense(@PathVariable("year") Integer year,
9597

9698
@Override
9799
public RepositoryLinksResource process(RepositoryLinksResource resource) {
98-
resource.add(ControllerLinkBuilder.linkTo(ExpenseEndpoint.class).withRel("expenses"));
100+
resource.add(WebMvcLinkBuilder.linkTo(ExpenseEndpoint.class).withRel("expenses"));
99101
return resource;
100102
}
101103
}

0 commit comments

Comments
 (0)