搶先一步
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。