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

How to solve the problem that SpringBoot does not read bootstrap.yml/properties files

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

Share

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

This article mainly explains "how to solve the problem that SpringBoot does not read bootstrap.yml/properties files". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn how to solve the problem that SpringBoot does not read bootstrap.yml/properties files.

Today I wrote and created a SpringBoot project, and the configuration file copied a bootstrap.yml from other projects.

The application.yml that I have been using before

I thought: the priority of application.yml is not as high as bootstrap.yml, and the bootstrap configuration file must be fine.

As soon as the project came, I found that the contents of the configuration file had not been read.

After that, I realized the difference between application.yml and bootstrap.yml by looking up various materials, which is not just a matter of priority.

Let's start with the cause of my problem:

If there is no dependency on spring-cloud-context in the SpringBoot project, the bootstrap.properties file will not be read

That is to say

Bootstrap.yml configuration is only used by SpringCloud projects.

If your project is only a SpringBoot project, only the application.yml configuration file will be recognized.

Since SpringCloud is built on SpringBoot, all SpringCloud project files will be identified, so it is said that priority will be given to SpringCloud projects. SpringCloud projects will give priority to reading the bootstrap configuration in reading the application configuration.

To quote a quote from the official website of Spring

A Spring Cloud application operates by creating a "bootstrap" context, which is a parent context for the main application. Out of the box it is responsible for loading configuration properties from the external sources, and also decrypting properties in the local external configuration files.

SpringCloud applications run under a "bootstrap" context.

This shows that the configuration of bootstrap is only used by SpringCloud applications.

What configuration is configured in application? What configuration is configured in bootstrap?

1. When using Spring Cloud Config Server, spring.application.name and spring.cloud.config.server.git.uri should be specified in bootstrap.yml

2. Some configurations of encryption and decryption should also be configured in bootstrap.

At this point, I believe that everyone on the "SpringBoot does not read bootstrap.yml/properties files how to solve the problem" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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