SpringBoot项目入门

使用 IDEA 快速搭建 SpringBoot 入门项目

一、构建SpringBoot项目

1.在这里插入图片描述
2. 这里的packaging是指打包方式,可以是jar包,也可以是war包在这里插入图片描述
3. 在这里插入图片描述
4. 在这里插入图片描述入门项目构建完成!

二、在pom.xml文件中添加依赖

自动生成的SpringBoot项目中已经生成下面的依赖文件

   <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>2.1.3.RELEASE</version>
       <relativePath/>
   </parent>  

添加依赖

	<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

三、编写启动类Demo01Application

@SpringBootApplication
public class Demo01Application {
   public static void main(String[] args) {
       SpringApplication.run(Demo01Application.class, args);
   }
}
  • 知识点:
    @EnableAutoConfiguration:表示开启自动化配置,由于项目添加了 spring-boot-starter-web 依赖,因此在开启了自动化配置之后会自动进行Spring SpringMVC 的配置。
    @SpringBootConfiguration:这是一个配置类,开发者可以在这个类中配置Bean 。
    @ComponentScan:完成包扫描(扫描该类所在的包以及子子孙孙的包)
  • 记:
    项目启动类中的 @ComponentScan注解,除了扫描 @Service 、@Repository、 @Component、 @Controller、 @RestController 等之外 ,也会扫描@Configuration 注解的类。
  • 也可以直接使用组合注解 @SpringBootApplication 来代替@EnableAutoConfiguration、
    @ComponentScan和@SpringBootConf iguration

在这里就是使用了 @SpringBootApplication 代替了这三个注解。

四、创建 SpringMVC中的控制器:HelloController

@RestController
public class HelloController {
    @GetMapping("/hello")
    public String hello () {
        return "hello spring boot !";
    }
}

五、启动项目

通过SpringBoot项目的启动类启动该项目。
在这里插入图片描述
在浏览器中访问该项目,出现如下图所示表示项目启动成功!
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值