Spring Boot for Rapid Application Development

Building Java applications using Spring Framework is pretty common. Spring creates repositories, service layers, and controllers for all exposed entities. Unfortunately, these classes are generally repetitive. Spring Roo tried to cut the overhead by automating this. Sadly, the use of AspectJ convoluted things devaluing the approach.

Spring Boot

Spring Boot removes a lot of the hassles of application development. Spring Boot applications can contain an embedded Tomcat to allow for a fat JAR deployment. This avoids the hassles of a managing a web container and WAR.  This works out really nicely if you use Heroku. Heroku requires you to provide your own container for Java applications.

To use Spring Boot in your Java project add the Spring Boot Parent POM:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.6.RELEASE</version>
</parent>

To execute a Spring Boot application with Maven add the following plugin to your POM:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <configuration>
        <mainClass>Add Application Class Here</mainClass>
        <cleanupDaemonThreads>false</cleanupDaemonThreads>
    </configuration>
</plugin>

This will allow you to use mvn exec:java to execute your application. This is useful when developing in Eclipse. If you use the resource plugin for property replacement in your application.yml, executing the Java application from Eclipse won’t handle the replacements appropriately.  For example:

info:
    build:
        artifact: @[email protected]
        name: @[email protected]
        description: @[email protected]
        version: @[email protected]

Using mvn exec:java the @[email protected] will be replaced with a real value. If you use Eclipse and Run as Java Application, this value is not replaced.

Simplified REST Resources

Applying the @RepositoryRestResource annotation to an interface replaces the repository, a service, and a controller to expose a Restful service.

@RepositoryRestResource
public interface ObjectRepository extends CrudRepository<Object, Long> {
}

This will expose a route /objects. This route will create GET, POST, PUT, and DELETE operations. The only downside is that Spring exposes a REST service that constrains to HATEOAS.