記錄第一用IDEA 學習springboot
SpringBoot的背景:
準生產級別的框架,方便用於開發和測試(不能直接上線)
類似於一個jar包,內置一個tomcat 和Servlet容器。
優點:
快速入門:
1.設置一個springBoot的parent
//Springboot的項目必須要將parent設置爲springboot的parent,該parent包含了大量默認的配置,大大簡化了我們的開發。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/>
</parent>
2.導入springBoot的wab支持
<!--引入一個web約束-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3.添加SpringBoot的插件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
4.編寫第一個SpringBoot的應用
@Controller //表明這是一個SpringMVC的Controller
@SpringBootApplication //SpringBoot的核心註解,目的是開啓自動配置
@Configuration //通過註解表明該類是一個spring配置,相當於一個xml文件
//springboot application啓動類都需要在類級別上加上@SpringBootApplication註解
public class DemoApplication {
@RequestMapping("hello")
@ResponseBody
public String hello() {
return "hello word!!!!";
}
//在main中啓動一個應用,方法的入口
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
錯誤 :Error:java: 無效的標記: -parameters
應該是編譯錯誤,所以就去改了 Use compiler
經默認的javac 改爲Eclispe
更改之後啓動就成成功了
出現了啓動成功界面
同時我們也可以看出我們的端口號是8080 內置的tomcat版本號。