領先一步
VMware 提供培訓和認證,以加速您的進度。
了解更多Spring Boot 0.5.0.M5 可在 Spring repo 中取得。 安裝和使用說明位於 專案網站 或 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
是一個共享的父上下文,可以在同一個模組中的其他應用程式重複使用。
這是一個簡短的 @Grab
在 Groovy 應用程式中的範例 (群組和版本資訊會自動新增)
@Grab("spring-boot-starter-actuator")
@RestController
class Example {
@RequestMapping("/")
String home() {
[message: 'Hello World']
}
}
這個應用程式可以獨立運行,例如,如果您使用 spring
shell 腳本啟動它,則可以在目前目錄中運行
$ spring run app.groovy
... (app starts up)
在瀏覽器中造訪 https://127.0.0.1:8080/,然後嘗試 https://127.0.0.1:8080/metrics。