springboot static静态方法获取yml配置文件

时间:2024-10-22 11:34:23

1、使用IDE打开springboot的代码工程

springboot static静态方法获取yml配置文件

2、 找到项目启动器同文件夹下的config文件夹,如果没有则新建

springboot static静态方法获取yml配置文件

3、创建java文件用于后面的测试

springboot static静态方法获取yml配置文件

4、 在步骤3中创建的java文件中写入如图所示的代码。注意注解是需要的

springboot static静态方法获取yml配置文件

5、 创建一个util.java的帮助工具类,在里面定义静态变量如下,并创建getter和setter静态方法。同时在yml文件中创建需要使用的变量,如图。

springboot static静态方法获取yml配置文件
springboot static静态方法获取yml配置文件

6、 回到步骤4汇总创建的文件中,写下如下代码。最后创建测试文件进行即可。@Configurationpublic class StaticConfig {@Value("${attachmentPrefixUrl}")private String attachmentPrefixUrl;@Beanpublic int initStatic(){PdfUtils.setAttachmentPrefixUrl(attachmentPrefixUrl);return 0;}}

springboot static静态方法获取yml配置文件

7、 如果您觉得有用,记得在下方点击投票、点赞、关注、留言,小编会定期奉上更多的惊喜哦,您的支持才是小编继续努力的动力,么么哒。

springboot static静态方法获取yml配置文件
© 手抄报圈