当前位置:网站首页>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)
边栏推荐
- Depth and breadth first traversal of tree (regardless of binary tree)
- 【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
- Uniapp skills - scrolling components -1
- Go: send the get request and parse the return JSON (go1.16.4)
- Leetcode-1175. Prime Arrangements
- Software testing is so hard to find, only outsourcing offers, should I go?
- Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
- MySQL data processing value addition, deletion and modification
- Resource Cost Optimization Practice of R & D team
- Summary of common error reporting problems and positioning methods of thrift
猜你喜欢

Implementation of Muduo accept connection, disconnection and sending data

Common network state detection and analysis tools
![[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心](/img/06/b71b505c7072d540955fda6da1dc1b.jpg)
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心

Summary of common error reporting problems and positioning methods of thrift

掌握Cypress命令行选项,是真正掌握Cypress的基础

Qt学习22 布局管理器(一)

Multi person collaborative data annotation based on Baidu brain easydata from scratch

Qt学习25 布局管理器(四)

“又土又穷”的草根高校,凭什么被称为“东北小清华”?

RichView TRVStyle ListStyle 列表样式(项目符号编号)
随机推荐
核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)
Golang — template
挡不住了,国产芯片再度突进,部分环节已进到4nm
How to promote the progress of project collaboration | community essay solicitation
Qt学习23 布局管理器(二)
软件测试工作那么难找,只有外包offer,我该去么?
Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
IBEM 数学公式检测数据集
GoLand 2021.1.1: configure the multi line display of the tab of the open file
Field problems in MySQL
Shell timing script, starting from 0, CSV format data is regularly imported into PostgreSQL database shell script example
Mastering the cypress command line options is the basis for truly mastering cypress
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
IBEM mathematical formula detection data set
Qt学习24 布局管理器(三)
Failure of vector insertion element iterator in STL
项目协作的进度如何推进| 社区征文
Common network state detection and analysis tools
JS new challenges
Qt学习21 Qt 中的标准对话框(下)






