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:
parent
1ad0bfaf29
commit
059a9e6a51
@ -95,7 +95,6 @@
|
|||||||
<guava.version>27.0.1-jre</guava.version>
|
<guava.version>27.0.1-jre</guava.version>
|
||||||
<xstream.version>1.4.11.1</xstream.version>
|
<xstream.version>1.4.11.1</xstream.version>
|
||||||
<modelmapper.version>2.3.5</modelmapper.version>
|
<modelmapper.version>2.3.5</modelmapper.version>
|
||||||
<spring-boot.version>2.1.9.RELEASE</spring-boot.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,14 +1,13 @@
|
|||||||
package com.baeldung.persistence.model;
|
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;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
|
import org.springframework.hateoas.RepresentationModel;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@JsonInclude(Include.NON_NULL)
|
@JsonInclude(Include.NON_NULL)
|
||||||
public class Customer extends ResourceSupport {
|
public class Customer extends RepresentationModel<Customer> {
|
||||||
private String customerId;
|
private String customerId;
|
||||||
private String customerName;
|
private String customerName;
|
||||||
private String companyName;
|
private String companyName;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.baeldung.persistence.model;
|
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 String orderId;
|
||||||
private double price;
|
private double price;
|
||||||
private int quantity;
|
private int quantity;
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package com.baeldung.web.controller;
|
package com.baeldung.web.controller;
|
||||||
|
|
||||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
|
||||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
|
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.hateoas.Link;
|
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;
|
||||||
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
|
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -41,7 +41,7 @@ public class CustomerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/{customerId}/orders", produces = { "application/hal+json" })
|
@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);
|
final List<Order> orders = orderService.getAllOrdersForCustomer(customerId);
|
||||||
for (final Order order : orders) {
|
for (final Order order : orders) {
|
||||||
final Link selfLink = linkTo(
|
final Link selfLink = linkTo(
|
||||||
@ -50,12 +50,12 @@ public class CustomerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Link link = linkTo(methodOn(CustomerController.class).getOrdersForCustomer(customerId)).withSelfRel();
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(produces = { "application/hal+json" })
|
@GetMapping(produces = { "application/hal+json" })
|
||||||
public Resources<Customer> getAllCustomers() {
|
public CollectionModel<Customer> getAllCustomers() {
|
||||||
final List<Customer> allCustomers = customerService.allCustomers();
|
final List<Customer> allCustomers = customerService.allCustomers();
|
||||||
|
|
||||||
for (final Customer customer : allCustomers) {
|
for (final Customer customer : allCustomers) {
|
||||||
@ -72,7 +72,7 @@ public class CustomerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Link link = linkTo(CustomerController.class).withSelfRel();
|
Link link = linkTo(CustomerController.class).withSelfRel();
|
||||||
Resources<Customer> result = new Resources<>(allCustomers, link);
|
CollectionModel<Customer> result = new CollectionModel<>(allCustomers, link);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,6 @@ jdbc.user=sa
|
|||||||
jdbc.pass=
|
jdbc.pass=
|
||||||
|
|
||||||
# hibernate.X
|
# hibernate.X
|
||||||
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
hibernate.dialect=com.baeldung.persistence.config.CustomH2Dialect
|
||||||
hibernate.show_sql=false
|
hibernate.show_sql=false
|
||||||
hibernate.hbm2ddl.auto=create-drop
|
hibernate.hbm2ddl.auto=create-drop
|
||||||
|
@ -60,7 +60,7 @@ public final class JacksonMarshaller implements IMarshaller {
|
|||||||
List<T> entities = null;
|
List<T> entities = null;
|
||||||
try {
|
try {
|
||||||
if (clazz.equals(Foo.class)) {
|
if (clazz.equals(Foo.class)) {
|
||||||
entities = objectMapper.readValue(resourcesAsString, new TypeReference<List<Foo>>() {
|
entities = objectMapper.readValue(resourcesAsString, new TypeReference<List<T>>() {
|
||||||
// ...
|
// ...
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user