之前沒有寫博客的習慣,平時都是本身用筆記記錄本身所遇到的問題。在今年3月份跳槽到了如今這家公司,版本控制用的git。而且編譯器用的是IDEA、項目用的是Spring Boot。對我來講一切都是新的,因此在開源中國註冊了帳號想把以前的筆記整理到這上邊來,同時有空也寫寫博客把本身學習過程給記錄一下。今天就從Spring Boot的第一個HelloSpringBoot開始吧!java
Spring Boot 文檔 :https://git.oschina.net/hyjob/spring-boot-reference-guide.gitgit
IDEA建立一個簡單的SpringBoot應用:spring
2.springboot
3.app
4.編寫Controlleride
@Controller public class InitController { @RequestMapping("/") @ResponseBody public String helloworld(){ return " hello world spring boot !"; } }
到這裏,啓動main函數。地址欄訪問http://localhost:8080/ 就好了。函數
SpringBoot有專屬的@RestController註解能夠替換掉 @Controller 和@ResponseBody註解。spring-boot
注意:SpringBoot啓動主類須要放在全部的package的最外層(推薦),由於springboot啓動時默認掃描springboot啓動類包以及子包下的類文件,這樣使得寫在其它package裏的類即便使用了註解也不能被掃描到。也能夠在springboot啓動類上加@ComponentScan註解去指定須要掃描的包。或者:@SpringBootApplication(scanBasePackages = "com")學習
package com.yiyoudao.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @ComponentScan(basePackages = "com") public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }