SpringBoot入门第二天

一.@ImportResource原生配置文件注入

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">

    <bean id="haha" class="com.atguigu.boot.bean.User">
        <property name="name" value="zhangsan"></property>
        <property name="age" value="18"></property>
    </bean>

@ImportResource("classpath:beans.xml")

二.配置绑定 (@ConfigurationProperties

1.需要加入容器

2.在需要访问的类中添加绑定会自动注册到容器中 (@EnableConfigurationProperties

三.@SpringBootConfiguration(@Configuration代表是一个配置类)

由@ComponentScan(指定包扫描)和@EnableAutoConfiguration(自动配置包)

总结:

1.SpringBoot会自动加载所有配置类

2.配置类按照条件生效

3.生效的配置类中给容器提供组件

4.容器中由组件,就有了功能

自定义配置:用户自己用@bean替换组件修改默认的值

四.开发技巧

1.Lombok简化JavaBean开发

@Data加载get,set方法

2.简化日志开发(@Sl4j

 3.dev-tools快速构建

4.Spring Initailizr(项目初始化向导)快速构建SpringBoot项目

 五.yaml配置文件

要点:

1.key: value kv之间有空格

2.大小写敏感

3.#注释

4.缩进表示同级关系

5.字符串不需要加引号

示例:

person:
  username: zhangsan
  boss: true
  birth: 2001/08/15
  age: 22
  interests:
    - 篮球
    - 足球
#interests: [篮球,足球]
  animals: [阿猫,阿狗]
  score: {english:99,math:100}
  salary:
    - 999.99
    - 999.98
  pet:
    name: 阿狗
    weigth: 100
  allPets:
    sick:
      - {name: 阿狗,weigth: 99.99}
      - name: 阿毛
        weigth: 88.88
    health: [{name: 阿花,weight: 101},
             {name: 阿呆,weight: 200}]

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值