如何解决SpringBootv2.1.3.RELEASE的whilescanninganalias的问题
这篇文章主要介绍“如何解决Spring Boot v2.1.3.RELEASE 的 while scanning an alias的问题”,在日常操作中,相信很多人在如何解决Spring Boot v2.1.3.RELEASE 的 while scanning an alias的问题问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何解决Spring Boot v2.1.3.RELEASE 的 while scanning an alias的问题”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
专注于为中小企业提供成都网站设计、网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业五台免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
初学 Spring Boot 框架,在搭建“优雅停服”的时候遇到问题,怎么也配置不通,有一系列问题(都是我自己的原因,太菜)。下面简单说一下,首先,我是用的 application.yml 配置文件进行配置的。这个就导致了配置以下
management.endpoints.web.exposure.include: *
再启动项目,会出现报错:
09:56:06.571 [main] ERROR org.springframework.boot.SpringApplication - Application run failed java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml' at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:554) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:500) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:467) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:448) at java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$7(ConfigFileApplicationListener.java:447) at java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:444) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:332) at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:207) at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:190) at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:177) at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:163) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347) at org.springframework.boot.SpringApplication.run(SpringApplication.java:306) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) at com.eric.diary.DiaryApplication.main(DiaryApplication.java:12) Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning an alias in 'reader', line 25, column 44: ... endpoints.web.exposure.include: * ^ (13) in 'reader', line 25, column 45: ... ndpoints.web.exposure.include: * ^ at org.yaml.snakeyaml.scanner.ScannerImpl.scanAnchor(ScannerImpl.java:1444) at org.yaml.snakeyaml.scanner.ScannerImpl.fetchAlias(ScannerImpl.java:916) at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:364) at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:227) at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:586) at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148) at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:124) at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:236) at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:227) at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:215) at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:144) at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:85) at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:123) at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:547) at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:161) at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:134) at org.springframework.boot.env.OriginTrackedYamlLoader.load(OriginTrackedYamlLoader.java:75) at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:50) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadDocuments(ConfigFileApplicationListener.java:572) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:526) ... 23 common frames omitted Disconnected from the target VM, address: '127.0.0.1:59532', transport: 'socket' Process finished with exit code 1
查了一些资料,发现 yml 的配置文件的特殊符号要加上单引号,按如下配置就可以解决此问题:
management.endpoints.web.exposure.include: '*'
题外话:
配置“优雅停服”本来都快成功了,出现这个错误,一度以为自己又配错了,又重新配了,耽误了半天。其实 Spring Boot 配置的 1.x 和 2.x 配置不一样,然后 application.properties 和 application.yml 也有一点查别。下面放出 2.1.3 的 Spring Boot “优雅停服”的配置,也算是一个记录吧:
#/actuator转换成/eric(你也可以写任意的,默认是/actuator) management.endpoints.web.base-path: /eric #激活所有的端点的web方式请求(也可以单独只暴露shutdown断点,有些人管这个叫暴露) management.endpoints.web.exposure.include: '*' #启用shutdown(启用Spring Boot的shutdown功能) management.endpoint.shutdown.enabled: true
到此,关于“如何解决Spring Boot v2.1.3.RELEASE 的 while scanning an alias的问题”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!
分享标题:如何解决SpringBootv2.1.3.RELEASE的whilescanninganalias的问题
文章出自:http://ybzwz.com/article/jpicji.html