這篇文章主要介紹“如何解決Spring Boot v2.1.3.RELEASE 的 while scanning an alias的問(wèn)題”,在日常操作中,相信很多人在如何解決Spring Boot v2.1.3.RELEASE 的 while scanning an alias的問(wèn)題問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”如何解決Spring Boot v2.1.3.RELEASE 的 while scanning an alias的問(wèn)題”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
專(zhuān)注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)五臺(tái)免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了成百上千企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
初學(xué) Spring Boot 框架,在搭建“優(yōu)雅停服”的時(shí)候遇到問(wèn)題,怎么也配置不通,有一系列問(wèn)題(都是我自己的原因,太菜)。下面簡(jiǎn)單說(shuō)一下,首先,我是用的 application.yml 配置文件進(jìn)行配置的。這個(gè)就導(dǎo)致了配置以下
management.endpoints.web.exposure.include: *
再啟動(dòng)項(xiàng)目,會(huì)出現(xiàn)報(bào)錯(cuò):
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
查了一些資料,發(fā)現(xiàn) yml 的配置文件的特殊符號(hào)要加上單引號(hào),按如下配置就可以解決此問(wèn)題:
management.endpoints.web.exposure.include: '*'
題外話(huà):
配置“優(yōu)雅停服”本來(lái)都快成功了,出現(xiàn)這個(gè)錯(cuò)誤,一度以為自己又配錯(cuò)了,又重新配了,耽誤了半天。其實(shí) Spring Boot 配置的 1.x 和 2.x 配置不一樣,然后 application.properties 和 application.yml 也有一點(diǎn)查別。下面放出 2.1.3 的 Spring Boot “優(yōu)雅停服”的配置,也算是一個(gè)記錄吧:
#/actuator轉(zhuǎn)換成/eric(你也可以寫(xiě)任意的,默認(rèn)是/actuator) management.endpoints.web.base-path: /eric #激活所有的端點(diǎn)的web方式請(qǐng)求(也可以單獨(dú)只暴露shutdown斷點(diǎn),有些人管這個(gè)叫暴露) management.endpoints.web.exposure.include: '*' #啟用shutdown(啟用Spring Boot的shutdown功能) management.endpoint.shutdown.enabled: true
到此,關(guān)于“如何解決Spring Boot v2.1.3.RELEASE 的 while scanning an alias的問(wèn)題”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!