当前位置:网站首页>28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
2022-07-03 13:28:00 【小枯林】
说明:
(1)为什么写了本篇博客?:
● 在【27:第三章:开发通行证服务:10:【注册/登录】接口】中,我们设置cookie的时候,cookie的域和path,我们都写死在了程序中;
● 很显然,在开发环境、测试环境、生产环境中,我们大概率需要修改;;同时,以后在生产环境中,如果也可能需要修改;
● 而,如果把这些信息写死在代码中,如果我们要修改,就是修改的java的类;而这是很不好的;
(2)以前遇到过的两种解决方案:
● 第一种方式:把信息写在application.properties这个项目的配置文件(这个配置文件,是Spring Boot项目的,核心的application配置文件)中;然后,在代码中可以利用@Value注解去获取;;;这在【Spring Boot入门七:【配置文件中,配置自定义属性】并【使用@Value注解去获取属性,以赋值给变量】;】和【Spring Boot电商项目35:商品模块二:【增加商品】接口之图片上传:【上传图片】接口开发;】中,都有比较详细的介绍;
● 第二种方式:我们创建一个配置文件(这个配置文件,不是Spring Boot项目的核心配置文件,就是我们瞎创建的一个文件)中;然后,创建一个“获取资源文件信息”的类,以属性文件的形式去获取信息;;;这在【19:第三章:开发通行证服务:2:在程序中,打通阿里云短信服务;】,有比较详细的介绍;
(3)本篇博客采取的做法就是(2)中的第一种方式;
目录
2.在BaseController的代码中,就可以取获取了;
一:【配置自定义属性】和【使用@Value注解,去获取】;
声明:开始前,请务必快速回顾下:以前的这两篇博客;
1.在【user】用户微服务的配置文件中,去设置属性;
2.在BaseController的代码中,就可以取获取了;
说明:
(1)一个特别需要说明的点:
可以这样理解,【user】引入了【api】之后,其自然也就引入了【api中的BaseController】;;;自然此时,【BaseController】,也可以认为是【user】中的内容了;
3.效果;
重新install一下整个项目,然后启动【user】用户微服务的主启动类;然后,去注册/登录;(PS:为了排除以前的干扰,最好清一下浏览的cookie)
边栏推荐
- Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
- [développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
- Unity render streaming communicates with unity through JS
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
- NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
- mysql中的字段问题
- SQL Injection (POST/Search)
- Unity Render Streaming通过Js与Unity自定义通讯
- SQL Injection (GET/Select)
- Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
猜你喜欢

JVM family - overview, program counter day1-1

3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)"/>MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)

Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
![[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes

Qt学习23 布局管理器(二)

Conversion function and explicit
![Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:](/img/2f/33504391a661ecb63d42d75acf3a37.png)
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:

RichView TRVStyle ListStyle 列表样式(项目符号编号)

Logback log sorting
随机推荐
MySQL 数据增删改查综合案例
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
mysql中的字段问题
3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
Go: send the get request and parse the return JSON (go1.16.4)
Unity Render Streaming通过Js与Unity自定义通讯
Dlopen() implements dynamic loading of third-party libraries
Common network state detection and analysis tools
Qt学习25 布局管理器(四)
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
网上开户哪家证券公司佣金最低,我要开户,网上客户经理开户安全吗
Sequence table (implemented in C language)
Replace the GPU card number when pytorch loads the historical model, map_ Location settings
Go 1.16.4: manage third-party libraries with Mod
SQL Injection (AJAX/JSON/jQuery)
The shadow of the object at the edge of the untiy world flickers, and the shadow of the object near the far point is normal
Go language unit test 3: go language uses gocovey library to do unit test
SQL Injection (GET/Search)






