Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to use ${} to inject values in the springboot configuration file

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "springboot configuration file using the value of ${} what are the ways", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn the "springboot configuration file using the value of ${} what are the ways to inject value" this article.

Use System.setProperty to set the parameter user: user-name: ${username} age: ${age} in springboot using the ${} injection value in the configuration file

Configuration file is written this way, we can use System.setProperty to set parameters, System.setProperty is equivalent to a static variable, stored in memory, using el expressions and @ value to get

Public static void main (String [] args) {System.setProperty ("username", "Zhang San"); System.setProperty ("age", "10");} @ Componentpublic class User {@ Value ("${user.user-name}") private String username; @ Value ("${user.age}") private String age SetterAndGetter @ Override public String toString () {return "User [username=" + username + ", age=" + age + "]";} User [username= Zhang San, age=10] configuration file self-scan

Familiar database configuration. Here we can use automatic scanning.

Here's jdbc.properties.

Driver=com.mysql.jdbc.Driverurl=jdbc:mysql://127.0.0.1:3306/test?autoReconnect=trueusername=rootpassword=root# defines the initial number of connections initialSize=5# defines the maximum number of connections maxActive=20# defines the maximum idle maxIdle=20# defines the minimum idle minIdle=1# defines the maximum waiting time maxWait=60000spring profile ${} the usage of the profile ${} is done without much to say.

The above is all the contents of the article "what are the ways to use ${} to inject values in the springboot configuration file?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report