Я получаю ошибку ниже для проекта Весеннее облако. В этом проекте я не делаю ничего особенного, кроме чтения файлов .properties из GIT.
Пожалуйста, расскажите, что еще нужно исправить здесь?
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:535) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:494) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:462) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$4(ConfigFileApplicationListener.java:444) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at java.lang.Iterable.forEach(Unknown Source) ~[na:1.8.0_151]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$5(ConfigFileApplicationListener.java:443) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at java.lang.Iterable.forEach(Unknown Source) ~[na:1.8.0_151]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:440) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:331) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:213) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:196) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:183) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:169) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:358) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:317) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at pluralsight.demo.PluralsightSpringcloudM2ConfigserverGitApplication.main(PluralsightSpringcloudM2ConfigserverGitApplication.java:12) [classes/:na]
Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing a block collection
in 'reader', line 17, column 17:
- "*/perf"
^
expected <block end>, but found Key
in 'reader', line 18, column 17:
uri: https://github.com/rseroter ...
^
Как мы можем решить приведенную ниже ошибку? application.yml
---
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/rseroter/pluralsight-spring-cloudconfig-wa-tolls
search-paths:
- 'station*'
repos:
perf:
pattern:
- "*/perf"
uri: https://github.com/rseroter/pluralsight-spring-cloudconfig-wa-tolls-perf
search-paths:
- 'station*'




Попробуйте удалить кавычки
---
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/rseroter/pluralsight-spring-cloudconfig-wa-tolls
search-paths:
- 'station*'
repos:
perf:
pattern:
- */perf ##as it was trying to match the whole pattern
uri: https://github.com/rseroter/pluralsight-spring-cloudconfig-wa-tolls-perf
search-paths:
- 'station*'
Если по-прежнему не работает, попробуйте следующее
repos:
perf:
pattern: xx*/perf, */pref ##as the fist character can't be a wild card but it can accept multiple value.
uri: https://github.com/rseroter/pluralsight-spring-cloudconfig-wa-tolls-perf
Также важно следить за правильным отступом при работе с файлами yml.
Эта ошибка указывает на проблему с форматированием файла application.yml. Вы можете проверить свой yml-файл онлайн: http://www.yamllint.com/
У меня такая же проблема, и я ее уже исправил. Если файл application.yml готов, вы можете попробовать очистить репозиторий maven (в Maven / репозиторий). Затем выполните обновление maven в своем проекте и запустите его снова.
Я не уверен насчет второго search-paths, думаю, вы вставили его туда по ошибке. Но для сообщений об ошибках в строках 17 и 18 это легко исправить:
Добавьте еще одно тире в строку, содержащую uri, чтобы она выглядела так:
repos:
perf:
pattern:
- */perf ##as it was trying to match the whole pattern
- uri: https://github.com/rseroter/pluralsight-spring-cloudconfig-wa-tolls-perf
То, что идет после pattern:, должно быть списком, и вам нужно добавить префикс - к элементам.
Я столкнулся с аналогичной проблемой ... одна из причин - неправильный интервал в файле yaml. Я решил, как показано ниже -
Пример -
incorrect one ->
RESERVATION:
registerHealthIndicator: true
slidingWindowSize: 100 --> this parameter have unnecessary spaces at beginning
the correct one is ->
RESERVATION:
registerHealthIndicator: true
slidingWindowSize: 100 --> correct as spaces at beginning removed
См. Изображение ниже -
Я получил эту ошибку сегодня, и я сначала не понял, потому что отступ в моем conf был хорошим. Потом я понял, что это потому, что кодировка моего application.yml была «Microsoft что-то» (предложено IntelliJ, точно не помню). Я просто скопировал свой conf, вставил его в SublimeText, удалил свой application.yml, затем воссоздал новый файл с тем же именем (так application.yml), скопировал то, что было в SublimeText, а затем вставил его в свой новый файл.
По-видимому, кодировка по умолчанию устранила проблему.
Если другие ответы не помогли, и вы используете IntelliJ, как я, попробуйте перезагрузить проект Gradle, который исправил его для меня.
Если мы используем возвышенное, мы могли бы выбрать симпатичный yaml, который может легко установить правильный синтаксис