Important annotations of Spring boot Framework Learning 3 annotation Method Read External resource profile

Source: Internet
Author: User

The main contents of this section:

1: How to get Configuration items in a configuration file in a non-annotated way

2: Use annotations to Get External properties file configuration items

Statement:

This article is an important note for the Spring boot framework to learn preschool Mastery (3)-Read the external resource profile by annotating the Edith accompany you learn series-Framework learning Spring boot Framework learning. You are welcome to comment

One: How to get Configuration items in a configuration file in a non-annotated way

Description

In the project, some information needs to be configured in the file.

For example, we will configure FTP-related files in fto.properties.

650) this.width=650; "src=" Http://n.sinaimg.cn//sinacn/20171019/4c5e-fymzzpv6908915.png "alt=" Spring Important annotations of boot Framework Learning 3 annotated way Read external resource profile "/>

Before we want to get information about FTP, such as:

Used in Java classes:

650) this.width=650; "src=" Http://n.sinaimg.cn//sinacn/20171019/7fce-fymzzpv6914130.png "alt=" Spring Important annotations of boot Framework Learning 3 annotated way Read external resource profile "/>

Tool Class: Getpropertiesvlaue class such as:

650) this.width=650; "src=" Http://n.sinaimg.cn//sinacn/20171019/9522-fymzzpv6914144.png "alt=" Spring Important annotations of boot Framework Learning 3 annotated way Read external resource profile "/>

In this way, you can get the values in the corresponding configuration file.

From the above, we can know that to get the values in the configuration file, you need to:

1: Need to know the filename (file name or file relative path)

2: Need to know the key in the get file.

such as the above:

static String Ftpserver = Getpropertiesvalue.getvalue (Ftpfile, "Ftpip");

This method is not feeling a bit troublesome.

Second: using annotations to Get External properties file configuration items

2.1: Annotations on the use of @propertysource and @value

Please look first, the following is the source of the demo:

650) this.width=650; "src=" Http://n.sinaimg.cn//sinacn/20171019/5ee1-fymzzpv6914154.png "alt=" Spring Important annotations of boot Framework Learning 3 annotated way Read external resource profile "/>

Source comments in the general meaning:

@configuration annotations are used in a class, and @propertysource is used for this annotation

The Key/value value in the corresponding file can be obtained from the propertysource annotation.

Next, let's take a look at the actual pseudo-code:

650) this.width=650; "src=" Http://n.sinaimg.cn//sinacn/20171019/76b4-fymzzpv6914165.png "alt=" Spring Important annotations of boot Framework Learning 3 annotated way Read external resource profile "/>

Description

@propertysource: The note is the file used to read the configured address in value.

@value (${}): Where the value in ${} is the value of the key in the corresponding configuration file


650) this.width=650; "src=" Http://n.sinaimg.cn//sinacn/20171019/1862-fymzzpv6913379.png "alt=" Spring Important annotations of boot Framework Learning 3 annotated way Read external resource profile "/>


Consider the question:

1: What if multiple profiles are written?

2: What if the configuration file configured in the value of Propertysource is not present?

You are welcome to learn the next article. In the next article, we will explain how to deal with the problem of thinking.

Welcome to the Gothic public: Edith Java

Welcome to visit Edith Personal website: www.kaigejava.com

This article source: HTTP://WWW.KAIGEJAVA.COM/ARTICLE/DETAIL/33

Related reading:

Spring Boot Framework Learn important notes for preschool mastery (4)-read external resource profiles by annotation 2

Important annotations of Spring boot Framework Learning 3 annotation Method Read External resource profile

Spring Boot Framework Learn important annotations for preschool Mastery (2)-Configure with Java configuration spring

Spring Boot Framework Learn the important annotations of preschool mastery (1)-sprng Java configuration method


This article from the "Edith Java" blog, reproduced please contact the author!

Important annotations of Spring boot Framework Learning 3 annotation Method Read External resource profile

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.