0
点赞
收藏
分享

微信扫一扫

SpringBoot 1-19

微言记 2022-09-21 阅读 84


​​https://www.bilibili.com/video/BV19K4y1L7MT?p=8​​

目录

​​springboot helloworld​​

​​ @RestController​​

​​查看官网文档​​

​​打包jar 插件 ​​

​​cmd 去除快速编辑模式​​

​​自定义以来版本​​

​​ spring boot自动配置​​

​​ 注册组件​​

​​组件命名 ​​

​​ 组件代理,依赖的Full和Lite 模式​​

​​ 底部组件解释​​

​​@import​​

​​两次shift,ctrl+h (查看继承树)​​

​​@ConditionalOnBean 条件装配 ​​

​​@ConfigurationProperties​​

​​通过配置文件初始化bean,注册组件component​​

​​@Component 和 @Bean 的区别​​

​​有空看​​

​​ 自动配置报告​​


​​ @Data​​

​​日志:@Slf4j ​​

​​dev-tools 自动更新代码,build​​

​​spring initalizr​​

springboot helloworld

SpringBoot 1-19_xml

SpringBoot 1-19_自定义_02

 @RestController

@RestController注解相当于@ResponseBody + @Controller合在一起的作用。

1) 如果只是使用@RestController注解Controller,则Controller中的方法无法返回jsp页面,或者html,配置的视图解析器 InternalResourceViewResolver不起作用,返回的内容就是Return 里的内容。

2) 如果需要返回到指定页面,则需要用 @Controller配合视图解析器InternalResourceViewResolver才行。
    如果需要返回JSON,XML或自定义mediaType内容到页面,则需要在对应的方法上加上@ResponseBody注解。

3)如果需要返回JSON,XML或自定义mediaType内容到页面,则需要在对应的方法上加上@ResponseBody注解。

SpringBoot 1-19_自定义_03

查看官网文档

​​https://spring.io/projects/spring-boot​​

SpringBoot 1-19_spring_04

SpringBoot 1-19_自定义_05

SpringBoot 1-19_自定义_06

​​https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.server​​

SpringBoot 1-19_自定义_07

打包jar 插件 

SpringBoot 1-19_xml_08

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

SpringBoot 1-19_xml_09

cmd 去除快速编辑模式

SpringBoot 1-19_spring_10

SpringBoot 1-19_xml_11

自定义以来版本

SpringBoot 1-19_xml_12

 

SpringBoot 1-19_spring_13

 spring boot自动配置

  • 自动配好Tomcat
  • 引入Tomcat依赖。
  • 配置Tomcat
  • 自动配好SpringMVC
  • 引入SpringMVC全套组件
  • 自动配好SpringMVC常用组件(功能)
  • 自动配好Web常见功能,如:字符编码问题
  • SpringBoot帮我们配置好了所有web开发的常见场景
  • 默认的包结构
  • 主程序所在包及其下面的所有子包里面的组件都会被默认扫描进来
  • 无需以前的包扫描配置
  • 想要改变扫描路径,@SpringBootApplication(scanBasePackages="com.atguigu")
  • 或者@ComponentScan 指定扫描路径

SpringBoot 1-19_spring_14

 

SpringBoot 1-19_自定义_15

SpringBoot 1-19_xml_16

 注册组件

SpringBoot 1-19_自定义_17

 

SpringBoot 1-19_spring_18

组件命名 

SpringBoot 1-19_xml_19

SpringBoot 1-19_自定义_20

SpringBoot 1-19_自定义_21

 组件代理,依赖的Full和Lite 模式

 

SpringBoot 1-19_xml_22

@Bean:表示一个方法实例化、配置或者初始化一个Spring IoC容器管理的新对象。
@Component: 自动被comonent扫描。 表示被注解的类会自动被component扫描
@Repository: 用于持久层,主要是数据库存储库。
@Service: 表示被注解的类是位于业务层的业务component。
@Controller:表明被注解的类是控制component,主要用于展现层 。

@Bean与@Component区别
@Component是 spring 2.5引入的,为了摆脱通过classpath扫描根据xml方式定义的bean的方式.

@Bean是spring 3.0 引入的,和 @Configuration一起工作,为了摆脱原先的xml和java config方式。

@Component与@Service区别

  • allowing for implementation classes to be autodetected through classpath scanning. 也就是@Service是一种具体的@Component,使得被注解类能通过classpath扫描被自动检测。

 底部组件解释

​​https://www.jianshu.com/p/e7a62409f682​​ 

@import

SpringBoot 1-19_xml_23

两次shift,ctrl+h (查看继承树)

condition :条件

SpringBoot 1-19_xml_24

@ConditionalOnBean 条件装配 

 

SpringBoot 1-19_spring_25

SpringBoot 1-19_spring_26

 

 

SpringBoot 1-19_xml_27

@ConfigurationProperties

通过配置文件初始化bean,注册组件component

SpringBoot 1-19_xml_28

 

SpringBoot 1-19_自定义_29

 

SpringBoot 1-19_xml_30

 

@Component 和 @Bean 的区别

Spring帮助我们管理Bean分为两个部分,一个是注册Bean,一个装配Bean。
完成这两个动作有三种方式,

一种是使用自动配置的方式、一种是使用JavaConfig的方式,一种就是使用XML配置的方式。

@Component 作用就相当于 XML配置

SpringBoot 1-19_spring_31


@Bean 需要在配置类中使用,即类上需要加上@Configuration注解 

SpringBoot 1-19_自定义_32

有空看

 

SpringBoot 1-19_spring_33

 自动配置报告

 

SpringBoot 1-19_xml_34

 引入依赖

 

SpringBoot 1-19_自定义_35

SpringBoot 1-19_自定义_36

 

SpringBoot 1-19_spring_37

SpringBoot 1-19_自定义_38

 

SpringBoot 1-19_自定义_39

 @Data

 

SpringBoot 1-19_xml_40

 

SpringBoot 1-19_xml_41

 

SpringBoot 1-19_xml_42

日志:@Slf4j 

 

SpringBoot 1-19_自定义_43

SpringBoot 1-19_spring_44

dev-tools 自动更新代码,build

spring initalizr

 

SpringBoot 1-19_xml_45

SpringBoot 1-19_spring_46

 

SpringBoot 1-19_自定义_47

 

SpringBoot 1-19_xml_48

 

举报

相关推荐

0 条评论