文字版本
//自动生成框架之后
1. 修改pom文件
<!--继承父项目-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<!--导入web依赖-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2.编写主程序(来启动springboot框架)
@SpringBootApplication:来标注springboot主程序类,说明这是一个springboot应用
3.启动主程序
编写main方法,使用SpringApplication类来启动框架
4.编写业务逻辑(hellowoldcontroller.class)
@Controller 可以处理请求
@RequestMapping 映射路径
@ResponseBody json
一.pom文件深究
springboothelloword的父项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
的父项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath>../../spring-boot-dependencies</relativePath>
</parent>
它来真正管理spring boot应用里面的所有的依赖版本
springboot的版本仲裁中心
以后导入依赖不需要写版本号,(没有在dependencies里面管理的依赖,自然需要管理版本号)
二.导入的依赖
<!--导入web依赖-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
spring-boot-starter web
spring-boot-starter------>springboot的场景启动器
spring boot 将所有的场景都抽取出来,做成一个个的starter(启动器),只需要在项目里面引入这些starter
相关场景的所有以来都会导进来,要用什么功能就导入什么场景的启动器
(启动器网址:https://docs.spring.io/spring-boot/docs/2.1.6.RELEASE/reference/html/using-boot-build-systems.html#using-boot-starter)
三.主程序类,主入口类
/**
* 来标注springboot主程序类,说明这是一个springboot应用
* **/
@SpringBootApplication
public class HelloWorldMainApplication {
public static void main(String[] args){
//spring应用启动起来(传入的类必须是@SpringBootApplication标注的类)
SpringApplication.run(HelloWorldMainApplication.class,args);
}
}
@SpringBootApplication 此注解标注在某一个类上,说明这个类是spring boot的主配置类
springboot就应该运行这个类的main方法来启动springboot应用
@SpringBootApplication是一个组合注解,包含一下几种注解
---------------------------------------------------------------------
--@Target({ElementType.TYPE})
--@Retention(RetentionPolicy.RUNTIME)
--@Documented
--@Inherited
--@SpringBootConfiguration
--@EnableAutoConfiguration
--@ComponentScan(
-- excludeFilters = {@Filter(
-- type = FilterType.CUSTOM,
-- classes = {TypeExcludeFilter.class}
-- ), @Filter(
-- type = FilterType.CUSTOM,
-- classes = {AutoConfigurationExcludeFilter.class}
-- )}
-- )
-- public @interface SpringBootApplication {
----------------------------------------
@SpringBootConfiguration ----->springboot的配置类
@EnableAutoConfiguration ----->开启自动配置功能
将主配置类(有@SpringBootApplication标注的类)所在的包及子包所有的
组件(比如hellowoldcontroller.java)都扫描到spring容器中
@Import({EnableAutoConfigurationImportSelector.class})
给容器中导入组件
EnableAutoConfigurationImportSelector:导入哪些组件的选择器
将所有需要导入的组件以全类名的方式返回,这些组件就会添加到容器中
会给容器中导入非常多的自动配置类