Spring Boot – Simplifying Spring for Everyone

Engineering
Phil Webb
August 06, 2013

(This 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:

Spring Boot in Context

The primary goals of Spring Boot are:

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 {

}

When you run this application using ‘spring run webapp.groovy’ a number things are happening:

The command line tool recognizes a number of different types of Spring Applications, including Web, Batch and Integration. There are a number of samples available in the GitHub repository.
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 {

}

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!
comments powered by Disqus

translate:
翻译:

使用“spring run”运行此应用程序时webapp.groovy“发生了很多事情:
您的脚本使用常用的“import”语句进行了增强,以节省您键入它们的时间
我们识别@ResponseBody注释并下载适当的Spring jar
我们自动创建Spring@Configuration,否则您需要编写
我们启动了一个嵌入式servlet容器,并在端口8080上处理传入的请求
命令行工具可以识别许多不同类型的Spring应用程序,包括Web、批处理和集成。GitHub存储库中提供了许多示例。
使用Java的Spring Boot
您不需要使用命令行工具或编写Groovy代码来获得Spring Boot的好处。我们还提供一流的Java支持。例如,下面是用Java编写的同一个应用程序:
进口启动.;
进口org.springframework.boot.autoconfigure.
;
进口原型.;
进口org.springframework.web.bind.annotation注释.
;
@控制器
@启用自动配置
公共类SampleController{
@请求映射(“/”)
@责任书
字符串主页(){
return“你好,世界!”;
}
public static void main(String[]args)引发异常{
SpringApplication.run文件(SampleController.class类,参数);
}
}
除了import语句之外,这个示例与前面的Groovy脚本的主要区别在于调用SpringApplication和@EnableAutoConfiguration注释的main()方法。
显然,使用Java,您还需要一个编译系统来编译和打包您的代码。我们提供了许多方便的“starter”pom,可以与Maven、Gradle或Ant+Ivy一起使用,以快速获取适当的依赖项。例如,上面的应用程序只需要一个对springbootstarterweb模块的依赖。
我们还提供Maven和Gradle插件,允许您打包一个完全独立的“fat jar”,可以从命令行启动:
$java-jarmyproject.jar项目
. ____ _ __ _ _
/ / __ _ () __ __ _
((){}’}’}’}’}’}/}}
/ )| |)| | | | | || (| | ) ) ) )
’ |
| .__|| ||| |__, | / / / /
=|_|======|/=////
●弹簧靴:v0.0.0.BUILD.SNAPSHOT版本
2013年7月31日00:08:16.117分信息56603—[main]o、 s.b.s.app.SampleApplication软件:启动SampleApplication第0.1.0版在带有PID 56603(/apps)的mycomputer上/我的app.jar由pwebb启动)
2013年7月31日00:08:16.166条信息56603—[main]ationConfigEmbeddedWebApplicationContext:正在刷新org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6e5a8246:启动日期[2013年7月31日星期三00:08:16 PDT];上下文层次结构的根
生产准备就绪
Spring Boot还包括一些有用的特性,这些特性在将应用程序推向生产环境时经常需要。我们可以自动提供web端点,您可以使用这些端点来监视应用程序的运行状况、提供基本的度量或分析生产问题(例如线程死锁)。我们还提供了一个新的@ConfigurationProperties注释,您可以使用它将应用程序配置外部化(包括对JSR-303@Valid注释的支持)。
转一圈
弹簧靴0.5.0.M1级现在在Spring里程碑存储库中可用。如果您想尝试本博客中的任何示例,请转到GitHub项目页面,在那里您可以找到详细的说明。我们正在积极寻找早期反馈,因此请随时提出问题或分叉存储库和提交拉请求。
SpringOne 2GX 2013即将推出
很快在圣克拉拉的斯普林贡预订您的房间。这只是一个最好的机会,可以直接了解所有发生的事情,并提供直接的反馈。预计今年会有一些重大的新公告。看看最近的博客文章,看看我的意思,还有更多的!
由DISPS提供的评论

文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树控制执行流程for91308 人正在系统学习中

来源:咔啡

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年4月15日
下一篇 2020年4月15日

相关推荐