When the springboot project started, an error occurred while reading the configuration file
Failed to load property source from location 'classpath:/application.yml'
......
org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
After searching for information, the reason was basically determined to be a problem with the file encoding format (the original yml file was in GBK format), so I changed the GBK format to UTF-8. After the change, I found that the Chinese comments in the previous file were garbled. The cause of the problem should be It comes from here, so I deleted all the comments and then started it normally.
Note: After the file format is changed, check whether there are garbled characters and comments will also be affected.
There is a hard-coded url in springBoot and sends an http request to obtain a video address.
The initial idea was like this, and then I considered that writing this way was not flexible enough. Because it is a springBoot project, it is very convenient to get the url directly in the configuration file.
Then the enemy who needs to get the Value uses the @VALUE annotation to get
but the life and death cannot be obtained there. The URL is always empty.
Finally I found that I had modified this variable with static before. Static initializes variables before the class is loaded. So @VALUE does not take effect at this time. So for NULL
, you only need to remove static.
The above is the detailed content of How to solve the error when springboot reads application.yml. For more information, please follow other related articles on the PHP Chinese website!