Just learning springboot (and newish to java: from .NET world)
Too PS course on spring-data and spring-data-rest. All went well
Made a test project connection to MS SQlServer. Created a few JPA Repos and unit tests pass for FindAll
I don't have a base-uri set in app properties and when explore the rest interface (with Postman) everything appears under /profile.
{
"_links": {
"self": {
"href": "http://localhost:8080/profile"
},
"users": {
"href": "http://localhost:8080/profile/users"
},
"tasks": {
"href": "http://localhost:8080/profile/tasks"
}
}
}
first question is, where does /profile come from?
JPA Repository is mainly used for managing the data in a Spring Boot Application. We all know that Spring is considered to be a very famous framework of Java. We mainly use this Spring Boot to create the Spring-based stand-alone and production-based applications with a very minimal amount of effort.
Spring Data REST can be used to expose HATEOAS RESTful resources around Spring Data repositories. Without writing a lot of code, we can expose RESTful API around Spring Data Repositories.
This repository is an interface that lets you perform various operations involving Person objects. It gets these operations by extending the PagingAndSortingRepository interface that is defined in Spring Data Commons. At runtime, Spring Data REST automatically creates an implementation of this interface.
CrudRepository mainly provides CRUD operations. PagingAndSortingRepository provide methods to perform pagination and sorting of records. JpaRepository provides JPA related methods such as flushing the persistence context and deleting of records in batch.
It's not a base path (url). It's a normal work of SDR:
A profile link, as defined in RFC 6906, is a place to include application-level details. The ALPS draft spec is meant to define a particular profile format, which we explore later in this section.
If you navigate into the profile link at
localhost:8080/profile
, you see content resembling the following:{ "_links" : { "self" : { "href" : "http://localhost:8080/profile" }, "persons" : { "href" : "http://localhost:8080/profile/persons" }, "addresses" : { "href" : "http://localhost:8080/profile/addresses" } } }
To work with your entities you have to use these links:
By the way you can set 'base path' in three ways:
In 'application.properties`
spring.data.rest.basePath=/api
Registering a bean
@Bean
public RepositoryRestConfigurer repositoryRestConfigurer() {
return new RepositoryRestConfigurerAdapter() {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.setBasePath("/api");
}
};
}
With a custom implementation of RepositoryRestConfigurer
@Component
public class CustomizedRestMvcConfiguration extends RepositoryRestConfigurerAdapter {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.setBasePath("/api");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With