2024.12.1(SpringBoot知识点总结)

创建Maven工程:使用IDEA工具创建一个Maven工程
1

添加SpringBoot的起步依赖:

org.springframework.boot spring-boot-starter-parent 2.0.1.RELEASE org.springframework.boot spring-boot-starter-web 编写SpringBoot引导类:

package com.itheima;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MySpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MySpringBootApplication.class);
}
}
编写Controller:

package com.itheima.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class QuickStartController {
@RequestMapping("/quick")
@ResponseBody
public String quick() {
return "springboot 访问成功!";
}
}
测试:执行SpringBoot起步类的主方法,控制台打印日志

自动配置原理

SpringBoot的自动配置注解是@EnableAutoConfiguration,它会在启动时通过@Import注解找到META-INF/spring.factories配置文件中的所有自动配置类,并对其进行加载

posted @ 2025-01-10 23:33  ysd666  阅读(11)  评论(0)    收藏  举报