当前位置:网站首页>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 线程
- C语言基础Day4-数组
- 数据源对象管理(第三方对象资源) & 加载properties文件
- Systick timer basic learning and hand tearing code
- 4年开发二面美团最终败给:volatile关键字作用和原理这道面试题
- [MCU simulation] (V) addressing mode - immediate addressing and register indirect addressing
- Detailed explanation of case when usage of SQL
- BiSeNetV1 面部分割
- Several methods of face detection
- [MCU simulation] (XVIII) control transfer instructions - empty operation instructions
猜你喜欢

The place where the dream begins ---- first knowing C language

Polynomial interpolation fitting (I)

3. Asynctool framework principle source code analysis

ResNet学习笔记

ncnn param文件及bin模型可视化解析

Snapshot: data snapshot (data disclosure method)

Code demonstration of fcos face detection model in openvino

无法访问此网站无法找到DNS地址DNS_PROBE_STARTED怎么办?

Tools and methods - Excel plug-in xltools

CorelDRAW 安装不了解决方法
随机推荐
BiSeNetV2-面部分割
SysTick定时器的基础学习以及手撕代码
Rsync - remote synchronization
Advanced usage of the responsibility chain pattern
Ncnn mat matrix class
The place where the dream begins ---- first knowing C language
重写equals为什么要重写hashcode
【单片机仿真】(八)指令系统 — 数据传送指令
仿射变换实现
要开源节流
【单片机仿真】(四)寻址方式 — 寄存器寻址与直接寻址
[MCU simulation] (XIV) instruction system bit operation instructions - bit data transmission instructions MOV, bit variable modification instructions
ncnn 线程
We should increase revenue and reduce expenditure
审视自己投资的路
内置键盘连续444
Understand the JVM memory structure in one article
ncnn 部分算子不支持的替换操作
Need to slow down a little
zsh: command not found: mysql