当前位置:网站首页>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


边栏推荐
- 无线用的鉴权代码
- 【PHP】tp6多表连接查询
- [single chip microcomputer simulation] (XII) instruction system logic operation instruction - logic XOR instruction XRL, accumulator clear 0 and reverse instruction
- 04_服务注册Eureka
- Pytorch best practices and code templates
- [MCU simulation] (I) proteus8.9 installation tutorial
- Go language realizes sending SMS verification code and logging in
- 【单片机仿真】(十二)指令系统逻辑运算指令 — 逻辑异或指令XRL、累加器清0和取反指令
- MySQL multi table query
- ncnn Mat矩阵类
猜你喜欢

C语言基础Day4-数组

Redis' simple dynamic string SDS

Detailed explanation of case when usage of SQL

Understand JVM garbage collection in one article

【剑指Offer】31-35题(判断一个序列是否是栈的出栈序列之一,层序打印二叉树以及分行打印、每行逆着打印),判断序列是否是二叉搜索树的后序遍历路径,二叉树找一条权值为K的路径,复制复杂链表

1. Introduction, analysis and implementation of asynctool framework

C language foundation day4 array

DDD 超越 MVC了吗

RESNET learning notes

数据源对象管理(第三方对象资源) & 加载properties文件
随机推荐
05_服务调用Ribbon
多锻炼身体有好处
Ncnn mat matrix class
【回归预测】基于粒子滤波实现锂离子电池寿命预测附matlab代码
MySQL multi table query
多项式插值拟合(一)
[MCU simulation] (XX) org - set start address
无法访问此网站无法找到DNS地址DNS_PROBE_STARTED怎么办?
2. Actual use of asynctool framework
乐视还有400多位员工?过着没有老板的神仙日子 官方出来回应了...
Go语言 实现发送短信验证码 并登录
【单片机仿真】(四)寻址方式 — 寄存器寻址与直接寻址
ResNet学习笔记
04_ Service registration Eureka
Oracle gets the last and first data (gets the first and last data by time)
[PHP] tp6 multi table connection query
【单片机仿真】(十一)指令系统逻辑运算指令 — 逻辑与指令ANL、逻辑或指令ORL
ubuntu清除cuda缓存
The place where the dream begins ---- first knowing C language
All dates in Oracle query time period