记录第一用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版本号。