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


边栏推荐
- 【单片机仿真】(十四)指令系统位操作类指令 — 位数据传送指令MOV、位变量修改指令
- 深入理解机器学习——类别不平衡学习(Imbalanced Learning):样本采样技术-[人工采样技术之ADASYN采样法]
- Mysql优化之索引
- First blog ----- self introduction
- 自动装配 & 集合注入
- mysql复制表
- [single chip microcomputer simulation] (XI) instruction system logic operation instruction - logic and instruction anl, logic or instruction ORL
- BiSeNetV1 面部分割
- Redis和其他数据库的比较
- Face key point detection
猜你喜欢

Pytorch best practices and code templates
![[PHP] tp6 multi table connection query](/img/f8/a3803f01820082792901bff98bb96c.png)
[PHP] tp6 multi table connection query

5. Is the asynctool framework flawed?

Tools and methods - Excel plug-in xltools

GraphQL初识

yolov5 ncnn 推理

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

Understand JVM garbage collection in one article

BiSeNetV1 面部分割
![[MCU simulation] (XX) org - set start address](/img/9e/4e44dd779b0de28a190d86fbb1c2c0.png)
[MCU simulation] (XX) org - set start address
随机推荐
无线用的鉴权代码
【单片机仿真】(二十一)DB(Define Byte)— 定义字节
RTX3090安装pytorch3D
Mysql优化之索引
04_服务注册Eureka
[MCU simulation] (XV) instruction system bit operation instructions - bit operation instructions, bit conditional transfer instructions
1. Introduction, analysis and implementation of asynctool framework
MySQL replication table
多项式插值拟合(三)
Is there really no way out for functional testing? 10K capping is never a joke
半年时间的思考
[MCU simulation] (XIII) instruction system logic operation instruction shift instruction
【单片机仿真】(六)寻址方式 — 变址寻址与相对寻址
[MCU simulation] (XVII) control transfer instructions - call and return instructions
多表查询——案例练习
2. Actual use of asynctool framework
04_ Service registration Eureka
内置键盘连续444
审视自己投资的路
While loop