博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring boot之读取自定义配置文件
阅读量:4228 次
发布时间:2019-05-26

本文共 381 字,大约阅读时间需要 1 分钟。

1,定义配置文件mypro.properties

#自定义配置base.redis.url=localhost:43434
2,在启动类上加上配置注解:

@PropertySource("classpath:mypro.properties")
public class Application {
}
这是定义要读取的properties文件的位置,另外,假如只读取该文件中的部分配置,可以在启动类上使用
@ConfigurationProperties(prefix = "base")注解来指定读取的前缀。建议不用设置前缀而是读取所有。

3,在需要使用的类中使用@Value(${base.redis.url})注解注入配置信息

//获取配置信息@Value("${spring.datasource.url}")private String url;

转载地址:http://xejqi.baihongyu.com/

你可能感兴趣的文章
Service Design for Six Sigma: A Roadmap for Excellence
查看>>
Maximum Security (3rd Edition)
查看>>
Discovering Knowledge in Data: An Introduction to Data Mining
查看>>
Computer Applications in Pharmaceutical Research and Development
查看>>
Software Measurement and Estimation: A Practical Approach
查看>>
Microsoft SQL Server 2005 Express Edition For Dummies
查看>>
Excel Pivot Tables Recipe Book: A Problem-Solution Approach
查看>>
USB Mass Storage: Designing and Programming Devices and Embedded Hosts
查看>>
JDBC Metadata, MySQL, and Oracle Recipes: A Problem-Solution Approach
查看>>
From VBA to VSTO: Is Excel's New Engine Right for You?
查看>>
Sams Teach Yourself Data Structures and Algorithms in 24 Hours
查看>>
Professional Windows Desktop and Server Hardening
查看>>
Software Estimation: Demystifying the Black Art (Best Practices
查看>>
Handbook of Research on Mobile Multimedia
查看>>
SQLite (Developer's Library)
查看>>
Measuring Information Systems Delivery Quality
查看>>
Windows 2000 Performance Guide
查看>>
Ajax And Php: Building Responsive Web Applications
查看>>
ASP.NET 2.0 Website Programming: Problem - Design - Solution
查看>>
XML in a Nutshell, Third Edition
查看>>