SpringBoot内部配置加载顺序
SpringBoot配置 加载 顺序 内部
2023-09-14 09:14:24 时间
SpringBoot内部配置加载顺序
简介:本文通过案例讲解,SpringBoot的内部配置的加载顺序。
概述
程序启动的时候,配置文件的加载顺序,优先级,由高到低为:
file:./config/
:当前目录下的/config
目录下。file:./
:当期项目的根目录。classpath:/config/
:classpath
的/config
目录。classpath:/
:classpath
的根目录。
file:./config/
file:./
classpath:/config/
classpath:/
合并集合
一共有 n 个数,编号是 1∼n,最开始每个数各自在一个集合中。
现在要进行 m 个操作,操作共有两种:
M a b,将编号为 a 和 b 的两个数所在的集合合并,如果两个数已经在同一个集合中,则忽略这个操作;
Q a b,询问编号为 a 和 b 的两个数是否在同一个集合中;
输入格式
第一行输入整数 n 和 m。
接下来 m 行,每行包含一个操作指令,指令为 M a b 或 Q a b 中的一种。
输出格式
对于每个询问指令 Q a b,都要输出一个结果,如果 a 和 b 在同一集合内,则输出 Yes,否则输出 No。
每个结果占一行。
数据范围
1≤n,m≤105
输入样例:
4 5
M 1 2
M 3 4
Q 1 2
Q 1 3
Q 3 4
输出样例:
Yes
No
Yes
提交代码
#include<iostream>
using namespace std;
const int N = 100010;
int n, m;
int p[N];
int find(int x) // 找到x的祖先节点
{
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
int main()
{
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) p[i] = i;
while (m--)
{
char op;
int a, b;
scanf (" %c%d%d", &op, &a, &b);
if (op == 'M') p[p[find(a)]] = find(b); // 让a的祖先节点指向b的祖先节点
else
{
if (find(a) == find(b)) puts("Yes");
else puts("No");
}
}
return 0;
}
import java.io.*;
public class Main
{
static int N = 100010;
static int n, m;
static int [] p = new int [N];
static int find(int x)
{
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader (System.in));
String [] str = reader.readLine().split(" ");
n = Integer.parseInt(str[0]);
m = Integer.parseInt(str[1]);
for (int i = 1; i <= n; ++ i) p[i] = i;
while (m -- > 0)
{
String op;
int a, b;
str = reader.readLine().split(" ");
op = str[0];
a = Integer.parseInt(str[1]);
b = Integer.parseInt(str[2]);
if (op.equals("M")) p[find(a)] = find(b);
else
{
if (find(a) == find(b)) System.out.println("Yes");
else System.out.println("No");
}
}
}
}
相关文章
- 宝塔部署 springboot 项目遇到的 一些bug处理方案
- SpringBoot之Mybatis操作中使用Redis做缓存
- SpringBoot ( 七 ) :springboot + mybatis 多数据源最简解决方案
- 学习SpringBoot零碎记录——配置应用URL名称
- springboot @PropertySource+@Value注入properties配置文件属性值
- 配置和修改springboot默认国际化文件
- SpringBoot配置属性之Server
- 【SpringBoot笔记01】SpringBoot框架介绍及其基础环境搭建
- Springboot调度任务:动态管理
- Springboot内置的工具类之Assert
- Springboot扩展点之BeanDefinitionRegistryPostProcessor
- Springboot定期自动清除日志信息
- SpringBoot 配置log日志持久化
- SpringBoot开启驼峰命名规范自动映射
- SpringBoot - resource资源文件的打包配置详解(指定资源文件位置)
- 【SpringBoot系列】最详细demo-- 声明式事务
- 【已解决详细demo】Springboot 一行代码实现文件上传 20个平台!少写代码到极致
- SpringBoot中调用第三方接口的三种方式
- SpringBoot 自动配置实现流程
- springboot系列——redisTemplate和stringRedisTemplate对比、redisTemplate几种序列化方式比较
- SpringBoot升级到2.0后默认时间格式变化_springboot接收date类型参数
- springboot+rabbitmq 之 消费端配置
- Docker 创建 springboot 项目镜像
- SpringBoot构建大数据开发框架
- 001-快速搭建Spring web应用【springboot 2.0.4】-gradle、springboot的启动过程分析、gradle多模块构建
- SSM,SpringBoot相关知识盲区整理
- SpringBoot---入门和配置
- SpringBoot使用@Valid注解校验参数无效
- springboot中的默认数据库连接池HikariDataSource
- SpringBoot利用外部配置,来设置jar包运行配置