Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.IllegalStateException:未能从位置';类路径:/application.yml';_Java_Spring Boot - Fatal编程技术网

java.lang.IllegalStateException:未能从位置';类路径:/application.yml';

java.lang.IllegalStateException:未能从位置';类路径:/application.yml';,java,spring-boot,Java,Spring Boot,对于Spring Cloud项目,我得到以下错误信息。在这个项目中,除了从GIT读取.properties文件之外,我没有做任何特殊的事情 请指导这里还有什么需要纠正的 java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml' at org.springframework.boot.context.config.ConfigFileA

对于Spring Cloud项目,我得到以下错误信息。在这个项目中,除了从GIT读取.properties文件之外,我没有做任何特殊的事情

请指导这里还有什么需要纠正的

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 ... 
                    ^
尝试删除引号

---
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文件时,查找正确的缩进也很重要。

此错误表示应用程序的格式有问题。yml 您可以在线验证您的yml文件:
我也有同样的问题,并且已经解决了。如果application.yml文件做得很好,您可以尝试清空maven存储库(位于maven/repository)。然后在您的项目中执行maven更新并再次运行它。

我不确定第二个
搜索路径,我想您错把它放在那里了。但对于第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

模式之后的内容:
应该是一个列表,您需要在项目前面加上
-

前缀,我也面临类似的问题。。。其中一个原因是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

请参阅下图-


我今天犯了这个错误,起初我不理解,因为我的配置缩进很好。然后我意识到这是因为我的
应用程序.yml
的编码是“Microsoft某物”(IntelliJ建议的,不记得很清楚)。我只是复制了我的conf,将其粘贴到SublimiteText中,删除了我的
application.yml
,然后用相同的名称重新创建了一个新文件(so
application.yml
),复制了SublimiteText中的内容,然后将其粘贴到我的新文件中。
显然,默认编码解决了这个问题。

如果其他答案没有帮助,而您像我一样使用IntelliJ,请尝试重新加载Gradle项目,这为我解决了问题。

如果我们使用sublime,我们可以选择漂亮的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