BAEL-3801: Update spring-boot-rest to use latest Spring Boot version (#8740)

* BAEL-3801: Upgrade to Spring Boot 2.2.2

* BAEL-3801: Fix JacksonMarshaller

* BAEL-3801: Get rid of deprecated HATEOAS classes

* BAEL-3801: Fix H2 tables drop order

* BAEL-3801: Remove commented property from pom.xml
This commit is contained in:
kwoyke 2020-02-19 22:36:27 +01:00 committed by GitHub
parent 1ad0bfaf29
commit 059a9e6a51
7 changed files with 41 additions and 17 deletions

View File

@ -95,7 +95,6 @@
<guava.version>27.0.1-jre</guava.version>
<xstream.version>1.4.11.1</xstream.version>
<modelmapper.version>2.3.5</modelmapper.version>
<spring-boot.version>2.1.9.RELEASE</spring-boot.version>
</properties>
</project>

View File

@ -0,0 +1,26 @@
package com.baeldung.persistence.config;
import org.hibernate.dialect.H2Dialect;
/**
* Since H2 1.4.200. the behavior of the drop table commands has changed.
* Tables are not dropped in a correct order.
* Until this is properly fixed directly in Hibernate project,
* let's use this custom H2Dialect class to solve this issue.
*
* @see <a href="https://hibernate.atlassian.net/browse/HHH-13711">https://hibernate.atlassian.net/browse/HHH-13711</a>
* @see <a href="https://github.com/hibernate/hibernate-orm/pull/3093">https://github.com/hibernate/hibernate-orm/pull/3093</a>
*/
public class CustomH2Dialect extends H2Dialect {
@Override
public boolean dropConstraints() {
return true;
}
@Override
public boolean supportsIfExistsAfterAlterTable() {
return true;
}
}

View File

@ -1,14 +1,13 @@
package com.baeldung.persistence.model;
import java.util.Map;
import org.springframework.hateoas.ResourceSupport;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.springframework.hateoas.RepresentationModel;
import java.util.Map;
@JsonInclude(Include.NON_NULL)
public class Customer extends ResourceSupport {
public class Customer extends RepresentationModel<Customer> {
private String customerId;
private String customerName;
private String companyName;

View File

@ -1,8 +1,8 @@
package com.baeldung.persistence.model;
import org.springframework.hateoas.ResourceSupport;
import org.springframework.hateoas.RepresentationModel;
public class Order extends ResourceSupport {
public class Order extends RepresentationModel<Order> {
private String orderId;
private double price;
private int quantity;

View File

@ -1,13 +1,13 @@
package com.baeldung.web.controller;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Resources;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.config.EnableHypermediaSupport;
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
import org.springframework.web.bind.annotation.GetMapping;
@ -41,7 +41,7 @@ public class CustomerController {
}
@GetMapping(value = "/{customerId}/orders", produces = { "application/hal+json" })
public Resources<Order> getOrdersForCustomer(@PathVariable final String customerId) {
public CollectionModel<Order> getOrdersForCustomer(@PathVariable final String customerId) {
final List<Order> orders = orderService.getAllOrdersForCustomer(customerId);
for (final Order order : orders) {
final Link selfLink = linkTo(
@ -50,12 +50,12 @@ public class CustomerController {
}
Link link = linkTo(methodOn(CustomerController.class).getOrdersForCustomer(customerId)).withSelfRel();
Resources<Order> result = new Resources<>(orders, link);
CollectionModel<Order> result = new CollectionModel<>(orders, link);
return result;
}
@GetMapping(produces = { "application/hal+json" })
public Resources<Customer> getAllCustomers() {
public CollectionModel<Customer> getAllCustomers() {
final List<Customer> allCustomers = customerService.allCustomers();
for (final Customer customer : allCustomers) {
@ -72,7 +72,7 @@ public class CustomerController {
}
Link link = linkTo(CustomerController.class).withSelfRel();
Resources<Customer> result = new Resources<>(allCustomers, link);
CollectionModel<Customer> result = new CollectionModel<>(allCustomers, link);
return result;
}

View File

@ -17,6 +17,6 @@ jdbc.user=sa
jdbc.pass=
# hibernate.X
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.dialect=com.baeldung.persistence.config.CustomH2Dialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=create-drop

View File

@ -60,7 +60,7 @@ public final class JacksonMarshaller implements IMarshaller {
List<T> entities = null;
try {
if (clazz.equals(Foo.class)) {
entities = objectMapper.readValue(resourcesAsString, new TypeReference<List<Foo>>() {
entities = objectMapper.readValue(resourcesAsString, new TypeReference<List<T>>() {
// ...
});
} else {