springboot学习笔记

视频地址:https://www.bilibili.com/video/BV1Lq4y1J77x?from=search&seid=15376935294305848216

一、必备链接

docs:https://docs.spring.io/spring-boot/docs/current/reference/html/

springboot-initializr:https://start.spring.io/

二、课程内容

1、读取配置文件

单个获取

@Value("${name}")

public String name;

------------------------------------------

全部获取

@Autowired

public Enviroument env;

env.getProperty("name");

------------------------------------------

映射实体类获取

@ConfigurationProperties(prefix = "person")

public class Person{

     String name;

    get/set...

}

@Autowired

public Person person;

person.getName();

三种方式,都可以读取.properties和.yaml/.yml配置内容

2、profile配置

多环境情况下,在 application.properties添加spring.profiles.active=dev,来说明启动开发环境application-dev.properties的配置。

3、配置文件优先级

 4、condition

@Configuration
public class UserConfig {

    @Bean
    //只有配置项存在才加载user Bean
    @ConditionalOnProperty(name = "user",havingValue = "lisi")
    public User user(){
        return new User();
    }
}

public class AutoConfigTest {
    public static void main(String[] args) {
        ConfigurableApplicationContext ctx = SpringApplication.run(Ay2proApplication.class,args);

        Object user = ctx.getBean("user");
        System.out.println(user);
    }
}

5、依赖关系图

6、Enable* 实质为Import,Import用于加载类,被Spring创建,放在IOC容器。

 

 

 7、打包发布

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值