Back Home

Hot Swapping

properly configured with the template cache disabled springboot is capable of quite acceptable hotswapping of resouces.

buildscript {
    repositories {
    dependencies {
        classpath 'org.springframework:springloaded:1.2.6.RELEASE'


apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'gs-serving-web-content'
    version =  '0.1.0'

repositories {

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'

springBoot {

bootRun {
    addResources = true

idea {
    module {
        inheritOutputDirs = false
        outputDir = file("$buildDir/classes/main/")

SpringBoot Web


While the nodejs community keeps spinning out tools for dependency managment including npm, bower, grunt-ish and now yarn. There is pretty simple maven, gradle integration for front end components with webjars

A middle ground is to extract the webjars (much like bower) to an asset directory (they can be webpacked afterwards) Jbake has a nice gradle unpack script at

Spring Boot Stats

Telegraf meets your requirements. It pulls data from jolokia and save to InfluxDB.

All you need to do is enable actuator and jolokia for SpringbootApplication, it is easy to add dependency to your maven:


After this you need configure telegraf to connect your web server and influxDB, here is an example config:

dc = "local-1"

interval = "10s"

context = "/jolokia"

name = "catalog"
host = "{web server ip address}"
port = "{web server port}"

name = "metrics"
mbean  = "org.springframework.boot:name=metricsEndpoint,type=Endpoint"
attribute = "Data"

url = "{http://influxdb:port}"
database = "telegraf"
precision = "s"

Make sure network of upper configuration is available, then you will get data in you influxDB.

Configure grafana to display the data stored in influxDB:

  • Add a influxDB type datasource
  • Create a new Dashboard and Graph panel.
  • Configure Graph panel and choose which filed you want to display in Metrics setting.
  • You will see the data on the panel.

SpringBoot Swagger

Swagger now branded as part of OpenAPI Specification provides to the means to edit and generate RESTful contract for your API, detailing all of its resources and operations in a human and machine readable format for easy development, discovery, and integration.

To round trip the api definition we

  • Workshop the swagger in the swagger editor
  • Generate the swagger springboot interface
  • modify and expose the springboot definition
  • test the api definition

Additionally the can the traditional jaxrs annotations be expose by spring boot swagger

The Swagger Editor is available as a git nodejs project. Alternativly it can be run as a docker project swagger-editor runs on port 8080 and can be exposed to your prefered port via the usual docker mapping.

sudo docker pull swaggerapi/swagger-editor
sudo docker run -d -p 8094:8080 swaggerapi/swagger-editor

This will open the default petstore example

See my swagger documentation for creating the api


Spring Cloud takes a very declarative approach, and often you get a lot of fetaures with just a classpath change and/or an annotation. Example application that is a discovery client:

public class Application {
	public static void main(String[] args) {, args);

Main Projects

Spring Data

Spring JDBC provides templates for reducing boilerplate code for accessing a database through plain old way - you write your own SQL queries.

Spring-ORM provides simplified templates for accessing databases through ORM technologies, such as Hibernate, My(i)Batis etc. When executing jdbc .. one can use standard try/catch on a transaction error or

Spring boot provides transaction annotation on a method

public class UserRepository {
    public User createUser(){
        //if user exist, throw DuplicateEmailException
void registerUser(User user) {
    try {
    catch(DuplicateEmailException e) {
       User registeredUser = userRepository.findByEmail(user.getEmail());

Spring Batch and Retry

//import the necessary classes
import org.springframework.batch.retry.RetryCallback;
import org.springframework.batch.retry.RetryContext;
import org.springframework.batch.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.batch.retry.policy.SimpleRetryPolicy;
// create the retry template
final RetryTemplate template = new RetryTemplate();
template.setRetryPolicy(new SimpleRetryPolicy(5));
final ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
// execute the operation using the retry template
template.execute(new RetryCallback<Remote>() {
  public Remote doWithRetry(final RetryContext context) throws Exception {
    return (Remote) Naming.lookup("rmi://somehost:2106/MyApp");

Spring Cloud Config


  • Distributed/versioned configuration
  • Service registration and discovery
  • Routing
  • Service-to-service calls
  • Load balancing
  • Circuit Breakers
  • Global locks
  • Leadership election and cluster state
  • Distributed messaging

* Centralized external configuration management backed by a git repository. The configuration resources map directly to Spring `Environment` but could be used by non-Spring applications if desired.

  • Integrates Spring Cloud Netflix - Integration with various Netflix OSS components (Eureka, Hystrix, Zuul, Archaius, etc.).
springboot.txt · Last modified: 2017/12/11 10:13 by root
RSS - 200 © CrosswireDigitialMedia Ltd