领先一步
VMware 提供培训和认证,助您加速进步。
了解更多Spring Boot 0.5.0.M5 可在 Spring 仓库 中获取。安装和使用说明请参见 项目网站 或 GitHub。包含大量新功能,包括:
@Grab 用法(见下面的示例)SpringApplicationBuilder,支持应用程序上下文层次结构等PropertiesLauncher,可以从运行时发现的属性启动 Java 应用程序(例如,从 lib 目录设置类路径)作为一名品鉴者,这里有一个在 Java 中使用 SpringApplicationBuilder 构建带有父上下文的应用程序的示例用法(如果您想从同一代码运行多个应用程序,这将非常有用)
@Configuration
@EnableAutoConfiguration
public class Server {
public static void main(String[] args) {
new SpringApplicationBuilder(Parent.class)
.child(Server.class)
.profiles("server")
.run(args);
}
// ... @Bean definitions follow
}
上面的 Parent.class 是一个共享的父上下文,可以在同一模块中的其他应用程序重复使用。
下面是一个 Groovy 应用程序中缩写的 @Grab 的示例(组和版本信息会自动添加)
@Grab("spring-boot-starter-actuator")
@RestController
class Example {
@RequestMapping("/")
String home() {
[message: 'Hello World']
}
}
此应用程序独立运行,例如,如果您使用 spring shell 脚本启动它,它将在当前目录中运行
$ spring run app.groovy
... (app starts up)
在浏览器中访问 https://:8080/,然后尝试访问 https://:8080/metrics。