// 一覧用テンプレート #topicpath ---- #ls2 ひさしぶりにSpringみてみたら、Spring のApplicationを作成するのにものすごく便利なフレームワークができてました。Spring Bootです。 [[Spring Boot>https://projects.spring.io/spring-boot/]] **やってみる [#b691ab09] 今回は、このチュートリアルから。 [[Getting Started · Building an Application with Spring Boot>https://spring.io/guides/gs/spring-boot/]] $ curl http://localhost:8080/ ってアクセス出来るWEBサーバを立ち上げてみます。 *** GitからClone [#cfbccf6d] $ git clone https://github.com/spring-guides/gs-spring-boot.git Cloning into 'gs-spring-boot'... remote: Counting objects: 970, done. remote: Total 970 (delta 0), reused 0 (delta 0), pack-reused 970 Receiving objects: 100% (970/970), 424.60 KiB | 189.00 KiB/s, done. Resolving deltas: 100% (620/620), done. *** ソースの確認 [#qc101f4c] $ cd gs-spring-boot/initial/ $ cat src/main/java/hello/Application.java package hello; import java.util.Arrays; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; @SpringBootApplication public class Application { public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(Application.class, args); System.out.println("Let's inspect the beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } } } $ cat src/main/java/hello/HelloController.java package hello; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestMapping; @RestController public class HelloController { @RequestMapping("/") public String index() { return "Greetings from Spring Boot!"; } } ***ビルドと実行 [#v9be699d] $ mvn package && java -jar target/gs-spring-boot-0.1.0.jar [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building gs-spring-boot 0.1.0 [INFO] ------------------------------------------------------------------------ ... 割愛 ... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.909 s [INFO] Finished at: 2017-01-15T18:39:30+09:00 [INFO] Final Memory: 29M/464M [INFO] ------------------------------------------------------------------------ . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.4.3.RELEASE) ... 割愛 ... viewControllerHandlerMapping viewResolver websocketContainerCustomizer welcomePageHandlerMapping *** アクセスしてみる [#g94a6a7a] $ curl http://localhost:8080/ Greetings from Spring Boot! WEBサーバ(組み込みのTomcatっぽい)が起動している事が確認できました。 ** 全体の構造の確認[#lf8cc780] Spring Bootによって起動される部分は Application.java です。 実際にクライアントから呼び出されるロジック部は HelloController.javaです。このクラスにはURLのマッピング @RequestMapping("/") などがannotationされたメソッドが定義されていて、クライアントから http://localhost:8080/ とURLのマッピングに従って呼び出すことができます。 **関連リンク [#s89856b6] -[[Getting Started · Building an Application with Spring Boot>https://spring.io/guides/gs/spring-boot/]] -[[ようやくSaStrutsを卒業してSpring bootデビューしたので良かった点と悪かった点を書いてみます>http://www.bunkei-programmer.net/entry/2016/10/19/004643]] **コンテンツ一覧 [#f3733076] #ls2 ---- SIZE(10){[[FrontPage]]}~ SIZE(10){現在のアクセス:&counter;}