Spring Boot - Simplifying Spring for Everyone
Join the DZone community and get the full member experience.
Join For Freethis blog post was written jointly by phil webb and dave syer ).
we are pleased to announce the first milestone release of a new project called spring boot .
spring boot aims to make it easy to create spring-powered, production-grade applications and services with minimum fuss. it takes an opinionated view of the spring platform so that new and existing users can quickly get to the bits they need. you can use it to create stand-alone java applications that can be started using
'java -jar'
or more traditional war deployments. we also provide a command line tool that runs 'spring scripts'.
the diagram below shows spring boot as a point of focus on the larger spring ecosystem. it presents a small surface area for users to approach and extract value from the rest of spring:
the primary goals of spring boot are:
- to provide a radically faster and widely accessible 'getting started' experience for all spring development
- to be opinionated out of the box, but get out of the way quickly as requirements start to diverge from the defaults
- to provide a range of non-functional features that are common to large classes of projects (e.g. embedded servers, security, metrics, health checks, externalized configuration)
spring boot does not generate code and there is absolutely no requirement for xml configuration.
spring scripts
spring boot ships with a small command line application that can be used to run 'spring scripts'. spring scripts are written in groovy , which means that you have a familiar java-like syntax, without so much boilerplate code. we are able to deduce a lot of information simply by looking at the way you have written your script. for example, here is a simple web application:
@controller class thiswillactuallyrun { @requestmapping("/") @responsebody string home() { return "hello world!" } }
when you run this application using
'spring run webapp.groovy'
a number things are happening:
-
your script is enhanced with common
'import'
statements to save you typing them -
we recognize the
@responsebody
annotation and download appropriate spring jars -
we automatically create the spring
@configuration
that you would otherwise need to write - we start up an embedded servlet container and handle incoming requests on port 8080
spring boot with java
you don't need use the command line tool or write groovy code to get the benefits of spring boot. we also have first class java support. for example, here is the same application written in java:
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); } }
other than import statements, the main difference between this example and the earlier groovy script is the
main()
method that calls
springapplication
and the
@enableautoconfiguration
annotation.
obviously with java you also need a build system to compile and package your code. we provide a number of convenient 'starter' poms that you can use with
maven
,
gradle
or
ant
+
ivy
to quickly grab appropriate dependencies. for example, the application above would need just a single dependency to the
spring-boot-starter-web
module.
we also provide maven and gradle plugins that allow you to package a fully self contained 'fat jar' that can be started from the command line:
$ java -jar myproject.jar . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: spring boot :: v0.0.0.build.snapshot 2013-07-31 00:08:16.117 info 56603 --- [ main] o.s.b.s.app.sampleapplication : starting sampleapplication v0.1.0 on mycomputer with pid 56603 (/apps/myapp.jar started by pwebb) 2013-07-31 00:08:16.166 info 56603 --- [ main] ationconfigembeddedwebapplicationcontext : refreshing org.springframework.boot.context.embedded.annotationconfigembeddedwebapplicationcontext@6e5a8246: startup date [wed jul 31 00:08:16 pdt 2013]; root of context hierarchy
production ready
spring boot also includes helpful features that you often need when you push an application into production. we can automatically provide web endpoints that you can use to monitor application health, provide basic metrics or use to analyze production issues (such as thread deadlocks). we also provide a new
@configurationproperties
annotation that you can use to externalize your application configuration (complete with support for jsr-303
@valid
annotations).
taking it for a spin
spring boot 0.5.0.m1 is available now in the spring milestone repository . if you want to try out any of the examples in this blog head over to the github project page where you find detailed instructions. we are actively looking for early feedback so please feel free to raise issues or fork the repository and submit pull requests.
springone 2gx 2013 is around the corner
book your place at springone in santa clara soon. it's simply the best opportunity to find out first hand all that's going on and to provide direct feedback. expect a number of significant new announcements this year. check recent blog posts to see what i mean and there is more to come!
Published at DZone with permission of Pieter Humphrey, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
5 Key Concepts for MQTT Broker in Sparkplug Specification
-
Seven Steps To Deploy Kedro Pipelines on Amazon EMR
-
Introduction To Git
-
Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
Comments