Author: | Marco Massenzio (marco@alertavert.com) |
---|---|
Revision: | 1.0-SNAPSHOT |
Created: | 2014-12-21 |
Updated: | 2014-12-23 |
This is a skeleton project to get going quickly with the Spring Boot framework, using Spring Data for the backend and Spring Rest for the frontend.
Just clone and modify.
The Persistence Layer is based on MongoDB, using DAOs to separate data concerns from business logic concerns.
Data access is via Spring Repositories
This project uses Spring as the main application framework, Spring Boot to manage the application, and Spring Data to manage the repositories.
Dependencies are managed via Maven (see the POM)
All endpoints are exposed via Spring REST and take the form:
[METHOD] /issues/{id}
where METHOD
is one of the usual {GET, POST, PUT, DELETE}
set and the {id}
uniquely identifies the entity in the DB.
Spring REST implements the HATEOAS principles, and enables discovery of endpoints and
resources; the starting point is the root
API [1]:
http://localhost:8080/api/v1
which returns something similar to:
{ "_links": { "issues": { "href": "http://localhost:8080/api/v1/issue{?page,size,sort}", "templated": true }, "profile": { "href": "http://localhost:8080/api/v1/alps" } } }
and from which a client application can progress to "discover" services and entities [#]_.
Spring REST also supports out-of-the-box search querying capabilities, linked to the methods exposed by the Spring Repositories, via URI parameters mapping.
To discover the search capabilities of a given entity (again, following HATEOAS principles) one uses the search resource:
http://localhost:8080/api/v1/issue/search
and queries against the entity can be executed by hitting an endpoint such as:
http://localhost:8080/api/v1/issue/search/findByReporter?reporter=user-1
which is mapped from the repository method:
@RepositoryRestResource(path = "issue") public interface IssueRepository extends PagingAndSortingRepository<Issue, String> { Issue findByReporter(@Param("reporter")String reporter); }
As this is a PagingAndSortingRepository
, the usual page
etc. query params are allowed too.
Testing and running locally is achieved via Maven:
mvn clean test mvn clean cobertura:cobertura test mvn clean cobertura:check test
the second and third invocation will, respectively, generate the code coverage report
(in target/site/cobertura/index.html
) and check that test coverage exceeds the minimum threshold
set in pom.xml
:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.6</version> <configuration> ... <check> <totalLineRate>70</totalLineRate> </check> </configuration> </plugin>
see the cobertura plugin documentation for more info.
Spring Boot generates the application as an embedded Tomcat JAR application, so this can
be run either via mvn
or directly via java
:
mvn spring-boot:run java -jar target/spring-template-1.0-SNAPSHOT.jar -Dsecurity.user.password=azekre7
see .travis.yml for an example of how to deploy and execute on a "blank" Linux (Debian) server.
TODO: experiment & document here
This software is (c) 2014 Marco Massenzio and is licensed according to the Apache 2 License ; see also the LICENSE file in this folder.
[1] | The root endpoint has been customized via the RestConfiguration class from the default |
/
.. [#] See the section about Resource Discoverability for more information.