Spring Boot's Getting started configuration (i)

Source: Internet
Author: User

YML, properties configuration file

Yml compared to the properties configuration file, Yml can omit unnecessary prefixes and look more layered. It is recommended to use the Yml file.

  

@Value

To obtain the corresponding value from the configuration item for the profile, the value @Value must be the same as the configuration entry in the configuration file, using the following method:

  

  

@ConfigurationProperties

When there are too many configuration items, it is more convenient to use @configurationproperties annotations. And you can group different configuration items. Example: Configuration items are divided into project and Johnson two different configuration items

The prefix that corresponds to the value of the @ConfigurationProperties. The property name must correspond to the configuration item. and implement the corresponding get, set method.

  

Here's how to use it:

  

@Component

Because in the persistence layer, the business layer and the control layer, respectively uses the @repository, the @Service and the @controller, because does not know this class belongs to which stratification plane, but also to spring management, therefore uses the @component.

Look at the project class and the Johnson class to see.

Multi-environment configuration

  In most development, general configuration items separate the production and test environments. If you are using the same profile, it can be cumbersome to constantly modify the configuration between production and test environments, and development efficiency will be very low.

and spring.profiles.active just can solve this problem.

  

Note: Naming requires specification, you must use the symbol "-" to differentiate files.

Wood is just a small white, if there is not good or better suggestions, please leave a message or send to my QQ mailbox [email protected]. Thank you all ~ (*^▽^*)

Spring Boot's Getting started configuration (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.