当前位置:网站首页>Data source object management (third-party object resources) & load properties file
Data source object management (third-party object resources) & load properties file
2022-07-19 03:10:00 【lwj_ 07】
One 、 Object data source management
Object data source management : in other words , Manage... Provided by third parties bean object
1.1、 Let's manage druid The example of Druid object resource is shown as follows :
First step : Import druid coordinate :

The second step :IOC Manage third parties in containers bean:
Be careful 1: When checking which method to inject , Enter the first bean In the object , Then press ctrl+F12 Check whether to use constructor or setter Injection mode
Be careful 2: Here is why we use value instead of ref: Because in DriudDataSource Among the objects , Ahead name The attribute value in this object is represented by the attribute , Such as :private String name Format exists , Not in BookDao bookdao = new BookDaoImpl(); Format exists , So want to use value Rather than using ref 【 That's what I learned earlier setter Injection handles simple types 】

The third step : obtain IOC Managed in a container bean Object calls methods in the object ( Here we are not connected to our database , Only print the memory address of the object )

The running results are as follows :

1.2、 Let's manage C3P0 An example of an object resource is shown below :
Be careful :C3P0 It is also used to connect to the database , and druid The difference is that the coordinates also need to be imported mysql drive jar Coordinates of the package
First step : Import C3P0 Coordinates and mysql drive jar Package coordinates

The second step :IOC Manage third parties in containers bean:

The third step : obtain IOC Managed in a container bean Object calls methods in the object ( Here we are not connected to our database , Only print the memory address of the object )

The running results are as follows :

Two 、 load properties file
load properties file : Just put the bean The dependencies made in the object value value , Write to properties The file of , And then get value value
2.1、 load properties The file steps are as follows

jdbc.properties file :

spring.xml file :

test:

2.2、 Verify whether you can get properties The data in the file
properties file :


BookDaoImpl:

The running results are as follows :

2.3、 A small problem ( stay properties The attribute name in the file conflicts with the attribute name of the environment variable )
: occasionally properties Attribute name in the file ( Such as :username) Will be compared with username Property name conflict , also properties The priority of the file is lower than that of the environment variable , So sometimes what you get is not properties Attribute values in the file , It's the environment variable


The running results are as follows :

The solution to this small problem is as follows :

The operation results are as follows :( You will find that there is no conflict , Because the resources in the environment variable are no longer loaded )

2.4、 Load multiple properties file


边栏推荐
- ncnn 部分算子不支持的替换操作
- [MCU simulation] (XIX) introduction to assembly, assembly instructions, pseudo instructions
- JDBC connection to MySQL database
- 【单片机仿真】(八)指令系统 — 数据传送指令
- 【PHP】tp6多表连接查询
- 【单片机仿真】(十二)指令系统逻辑运算指令 — 逻辑异或指令XRL、累加器清0和取反指令
- OpenVINO中的FCOS人脸检测模型代码演示
- 人脸检测几种方法
- Is there really no way out for functional testing? 10K capping is never a joke
- Fiddler抓包
猜你喜欢
![深入理解机器学习——类别不平衡学习(Imbalanced Learning):样本采样技术-[人工采样技术之SMOTE采样法及Borderline-SMOTE采样法]](/img/9f/a0d03b23e66849f12150f9a72f36c5.png)
深入理解机器学习——类别不平衡学习(Imbalanced Learning):样本采样技术-[人工采样技术之SMOTE采样法及Borderline-SMOTE采样法]

Mysql优化之索引

SysTick定时器的基础学习以及手撕代码

人脸检测几种方法

人脸关键点检测

【NoSQL】redis高可用和持久化

Face key point detection

Letv a plus de 400 employés? Le jour de l'immortel sans patron, les autorités ont répondu...

Full virtualization and semi virtualization

Advanced usage of the responsibility chain pattern
随机推荐
Ncnn mat matrix class
这是数学的问题
【单片机仿真】(九)指令系统 — 算术运算指令 之 ADD、ADDC、SUBB、INC、DEC、DA
[MCU simulation] (XV) instruction system bit operation instructions - bit operation instructions, bit conditional transfer instructions
功能测试真的没有出路了吗?10k封顶从来不是开玩笑的.....
一个优酷VIP会员帐号可以几个人用的设备同时登录如何共享多人使用优酷会员账号?
RTX3090安装pytorch3D
JPA初识(ORM思想、JPA的基本操作)
MySQL数据库中的事务和存储引擎
【单片机仿真】(十六)控制转移类指令 — 无条件转移指令、条件转移指令
4年开发二面美团最终败给:volatile关键字作用和原理这道面试题
Understand the JVM memory structure in one article
多锻炼身体有好处
2022-07-16:以下go语言代码输出什么?A:[];B:[5];C:[5 0 0 0 0];D:[0 0 0 0 0]。 package main import ( “fmt“ )
需要慢一点点
Graphql first acquaintance
【单片机仿真】(二)keil 安装教程
Multi table query - case exercise
[single chip microcomputer simulation] (XII) instruction system logic operation instruction - logic XOR instruction XRL, accumulator clear 0 and reverse instruction
工具及方法 - Excel插件XLTools