#514 - Prepare upgrade to Spring Data release train Moore.
Upgrade to latest versions of Spring HATOEAS and Spring Plugin.
This commit is contained in:
committed by
Oliver Drotbohm
parent
e1a739a3d6
commit
fb8dccd9d4
@@ -30,7 +30,13 @@
|
|||||||
<profile>
|
<profile>
|
||||||
<id>spring-data-next-releasetrain</id>
|
<id>spring-data-next-releasetrain</id>
|
||||||
<properties>
|
<properties>
|
||||||
<elasticsearch.version>6.5.0</elasticsearch.version>
|
<elasticsearch.version>6.6.0</elasticsearch.version>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>spring-data-next-releasetrain-released</id>
|
||||||
|
<properties>
|
||||||
|
<elasticsearch.version>6.6.0</elasticsearch.version>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|||||||
@@ -13,5 +13,12 @@
|
|||||||
|
|
||||||
<name>Spring Data JDBC - Basic usage examples</name>
|
<name>Spring Data JDBC - Basic usage examples</name>
|
||||||
<description>Sample project demonstrating Spring Data JDBC features</description>
|
<description>Sample project demonstrating Spring Data JDBC features</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
8
pom.xml
8
pom.xml
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<apt.version>1.1.3</apt.version>
|
<apt.version>1.1.3</apt.version>
|
||||||
<lombok.version>1.18.0</lombok.version>
|
<lombok.version>1.18.4</lombok.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
@@ -49,12 +49,16 @@
|
|||||||
<id>spring-data-next-releasetrain</id>
|
<id>spring-data-next-releasetrain</id>
|
||||||
<properties>
|
<properties>
|
||||||
<spring-data-releasetrain.version>Moore-BUILD-SNAPSHOT</spring-data-releasetrain.version>
|
<spring-data-releasetrain.version>Moore-BUILD-SNAPSHOT</spring-data-releasetrain.version>
|
||||||
|
<spring-hateoas.version>1.0.0.BUILD-SNAPSHOT</spring-hateoas.version>
|
||||||
|
<spring-plugin.version>2.0.0.BUILD-SNAPSHOT</spring-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
<profile>
|
<profile>
|
||||||
<id>spring-data-next-releasetrain-released</id>
|
<id>spring-data-next-releasetrain-released</id>
|
||||||
<properties>
|
<properties>
|
||||||
<spring-data-releasetrain.version>Lovelace-SR3</spring-data-releasetrain.version>
|
<spring-data-releasetrain.version>Moore-M2</spring-data-releasetrain.version>
|
||||||
|
<spring-hateoas.version>1.0.0.M1</spring-hateoas.version>
|
||||||
|
<spring-plugin.version>2.0.0.M1</spring-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import org.springframework.data.geo.Distance;
|
|||||||
import org.springframework.data.geo.Metrics;
|
import org.springframework.data.geo.Metrics;
|
||||||
import org.springframework.data.geo.Point;
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
|
import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
|
||||||
|
import org.springframework.hateoas.LinkRelation;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -89,7 +90,8 @@ class StoresController {
|
|||||||
model.addAttribute("selectedDistance", distance.orElse(DEFAULT_DISTANCE));
|
model.addAttribute("selectedDistance", distance.orElse(DEFAULT_DISTANCE));
|
||||||
model.addAttribute("location", point);
|
model.addAttribute("location", point);
|
||||||
model.addAttribute("locations", KNOWN_LOCATIONS);
|
model.addAttribute("locations", KNOWN_LOCATIONS);
|
||||||
model.addAttribute("api", entityLinks.linkToSearchResource(Store.class, "by-location", pageable).getHref());
|
model.addAttribute("api",
|
||||||
|
entityLinks.linkToSearchResource(Store.class, LinkRelation.of("by-location"), pageable).getHref());
|
||||||
|
|
||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2018 the original author or authors.
|
* Copyright 2014-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -32,18 +32,18 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
import org.springframework.boot.web.server.LocalServerPort;
|
import org.springframework.boot.web.server.LocalServerPort;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.hateoas.CollectionModel;
|
||||||
|
import org.springframework.hateoas.EntityModel;
|
||||||
import org.springframework.hateoas.Link;
|
import org.springframework.hateoas.Link;
|
||||||
import org.springframework.hateoas.Links;
|
import org.springframework.hateoas.Links;
|
||||||
import org.springframework.hateoas.MediaTypes;
|
import org.springframework.hateoas.MediaTypes;
|
||||||
import org.springframework.hateoas.PagedResources;
|
import org.springframework.hateoas.PagedModel;
|
||||||
import org.springframework.hateoas.PagedResources.PageMetadata;
|
import org.springframework.hateoas.PagedModel.PageMetadata;
|
||||||
import org.springframework.hateoas.Resource;
|
|
||||||
import org.springframework.hateoas.Resources;
|
|
||||||
import org.springframework.hateoas.client.Traverson;
|
import org.springframework.hateoas.client.Traverson;
|
||||||
import org.springframework.hateoas.client.Traverson.TraversalBuilder;
|
import org.springframework.hateoas.client.Traverson.TraversalBuilder;
|
||||||
import org.springframework.hateoas.mvc.TypeReferences.PagedResourcesType;
|
import org.springframework.hateoas.server.core.TypeReferences.CollectionModelType;
|
||||||
import org.springframework.hateoas.mvc.TypeReferences.ResourceType;
|
import org.springframework.hateoas.server.core.TypeReferences.EntityModelType;
|
||||||
import org.springframework.hateoas.mvc.TypeReferences.ResourcesType;
|
import org.springframework.hateoas.server.core.TypeReferences.PagedModelType;
|
||||||
import org.springframework.http.RequestEntity;
|
import org.springframework.http.RequestEntity;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.web.client.RestOperations;
|
import org.springframework.web.client.RestOperations;
|
||||||
@@ -90,16 +90,16 @@ public class StarbucksClient {
|
|||||||
parameters.put("location", "40.740337,-73.995146");
|
parameters.put("location", "40.740337,-73.995146");
|
||||||
parameters.put("distance", "0.5miles");
|
parameters.put("distance", "0.5miles");
|
||||||
|
|
||||||
PagedResources<Resource<Store>> resources = builder.//
|
PagedModel<EntityModel<Store>> resources = builder.//
|
||||||
withTemplateParameters(parameters).//
|
withTemplateParameters(parameters).//
|
||||||
toObject(new PagedResourcesType<Resource<Store>>() {});
|
toObject(new PagedModelType<EntityModel<Store>>() {});
|
||||||
|
|
||||||
PageMetadata metadata = resources.getMetadata();
|
PageMetadata metadata = resources.getMetadata();
|
||||||
|
|
||||||
log.info("Got {} of {} stores: ", resources.getContent().size(), metadata.getTotalElements());
|
log.info("Got {} of {} stores: ", resources.getContent().size(), metadata.getTotalElements());
|
||||||
|
|
||||||
StreamSupport.stream(resources.spliterator(), false).//
|
StreamSupport.stream(resources.spliterator(), false).//
|
||||||
map(Resource::getContent).//
|
map(EntityModel::getContent).//
|
||||||
forEach(store -> log.info("{} - {}", store.name, store.address));
|
forEach(store -> log.info("{} - {}", store.name, store.address));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,14 +112,15 @@ public class StarbucksClient {
|
|||||||
|
|
||||||
URI uri = URI.create(String.format(SERVICE_URI, port));
|
URI uri = URI.create(String.format(SERVICE_URI, port));
|
||||||
RequestEntity<Void> request = RequestEntity.get(uri).accept(HAL_JSON).build();
|
RequestEntity<Void> request = RequestEntity.get(uri).accept(HAL_JSON).build();
|
||||||
Resource<Object> rootLinks = restOperations.exchange(request, new ResourceType<Object>() {}).getBody();
|
EntityModel<Object> rootLinks = restOperations.exchange(request, new EntityModelType<Object>() {}).getBody();
|
||||||
Links links = new Links(rootLinks.getLinks());
|
Links links = rootLinks.getLinks();
|
||||||
|
|
||||||
// Follow stores link
|
// Follow stores link
|
||||||
|
|
||||||
Link storesLink = links.getLink("stores").expand();
|
Link storesLink = links.getRequiredLink("stores").expand();
|
||||||
|
|
||||||
request = RequestEntity.get(URI.create(storesLink.getHref())).accept(HAL_JSON).build();
|
request = RequestEntity.get(URI.create(storesLink.getHref())).accept(HAL_JSON).build();
|
||||||
Resources<Store> stores = restOperations.exchange(request, new ResourcesType<Store>() {}).getBody();
|
CollectionModel<Store> stores = restOperations.exchange(request, new CollectionModelType<Store>() {}).getBody();
|
||||||
|
|
||||||
stores.getContent().forEach(store -> log.info("{} - {}", store.name, store.address));
|
stores.getContent().forEach(store -> log.info("{} - {}", store.name, store.address));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
package example.springdata.rest.uris;
|
package example.springdata.rest.uris;
|
||||||
|
|
||||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||||
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
|
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,16 +25,16 @@ import org.springframework.stereotype.Component;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter {
|
public class SpringDataRestCustomization implements RepositoryRestConfigurer {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter#configureRepositoryRestConfiguration(org.springframework.data.rest.core.config.RepositoryRestConfiguration)
|
* @see org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer#configureRepositoryRestConfiguration(org.springframework.data.rest.core.config.RepositoryRestConfiguration)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
|
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
|
||||||
|
|
||||||
config.withEntityLookup().//
|
config.withEntityLookup() //
|
||||||
forRepository(UserRepository.class, User::getUsername, UserRepository::findByUsername);
|
.forRepository(UserRepository.class, User::getUsername, UserRepository::findByUsername);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
package example.springdata.rest.uris;
|
package example.springdata.rest.uris;
|
||||||
|
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
|
import lombok.experimental.NonFinal;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ import org.springframework.data.annotation.Id;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
|
@NonFinal
|
||||||
@Value
|
@Value
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import org.springframework.data.rest.core.support.EntityLookupSupport;
|
|||||||
/**
|
/**
|
||||||
* Custom {@link EntityLookup} to replace the usage of the database identifier in item resource URIs with the username
|
* Custom {@link EntityLookup} to replace the usage of the database identifier in item resource URIs with the username
|
||||||
* property of the {@link User}. This one is not really used out of the box as it's not a Spring bean. It's just a
|
* property of the {@link User}. This one is not really used out of the box as it's not a Spring bean. It's just a
|
||||||
* sample of how to deploy a customization in non-Java 8 environments which can't use the fluent API in use in
|
* sample of how to deploy a customization in pre-Java 8 environments which can't use the fluent API in use in
|
||||||
* {@link SpringDataRestCustomization}.
|
* {@link SpringDataRestCustomization}.
|
||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
@@ -54,4 +54,13 @@ public class UserEntityLookup extends EntityLookupSupport<User> {
|
|||||||
public Optional<User> lookupEntity(Object id) {
|
public Optional<User> lookupEntity(Object id) {
|
||||||
return repository.findByUsername(id.toString());
|
return repository.findByUsername(id.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.rest.core.support.EntityLookup#getLookupProperty()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Optional<String> getLookupProperty() {
|
||||||
|
return Optional.of("username");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user