Spring Boot is the last Smart micro-service offered by the big Spring. This post series will try to explain how to go with such framework to publish a small blog application to Heroku with a minimalist but usefull guide.

Pre-requisite

We want an angularjs based front-end, and a Spring-boot backend, providing some basic internal metrics about JVM and Business metrics.

Front-End

So build a front app with the famous yeoman.io:

$> yo angular myApp

Then after some judicious choice, you would get a nice ready-to-use angularjs application.

You would have to add a service for post management, and a home controller:

$> yo angular:controller Post
$> yo angular:service Post

Back-end

The backend will be provided trhough a small maven project, see quick-start for details.

But what you need to know is all in the pom.xml file:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.2.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

With such dependencies, your project is now a simple Spring-Boot ready to run application.

Now add a simple class:

package com.webcontext.apps.demo.dablog;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}

An now try to run it with the following command:

$ mvn spring-boot:run

and access the http://localhost:9000/

References

Sources are stored on my own github.com

Publicités