下麵創建一個SpringBoot入門項目: 1.pom.xml 2.代碼: ...
1.創建獨立的Spring應用程式. 2.嵌入tomcat,Jetty或者Undertow,無需部署war文件; 3.允許通過Maven來獲取starter; 4.儘可能的自動配置Spring. 5.提供生產就緒型功能,如指標,健康檢查和外部配置. 6.絕對沒有代碼生成,對xml沒有要求配置.
下麵創建一個SpringBoot入門項目:
1.pom.xml
<!-- AOP --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <!-- web開發包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 載入測試包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
2.代碼:
//@SpringBootApplication @Controller //啟動spring boot自動裝配. @EnableAutoConfiguration public class DemoApplication { @RequestMapping("/test") @ResponseBody public Map<String,Object> test(){ Map<String,Object> map = new HashMap<String,Object>(); map.put("key","value"); map.put("key2","value"); return map; } public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }