使⽤SpringBoot的yml⽂件配置时踩的⼀个坑
问题描述:使⽤SpringBoot整合redis进⾏yml配置的时候,启动⼯程报错,提⽰加载l配置⽂件失败:
17:18:27.430 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/l'
at org.t.config.ConfigFileApplicationListener$Loader.loadIntoGroup(ConfigFileApplicationListener.java:476)
at org.t.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:465)
at org.t.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:386)
at org.t.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:225)
at org.t.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:195)
at org.t.ApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:182) at org.t.ApplicationEvent(ConfigFileApplicationListener.java:168)
at t.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at t.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at t.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.t.vironmentPrepared(EventPublishingRunListener.java:74)
at org.springframework.vironmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.zhaopin.ImccApplication.main(ImccApplication.java:10)
flect.NativeMethodAccessorImpl.invoke0(Native Method)
flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at flect.Method.invoke(Method.java:498)
at cution.application.AppMain.main(AppMain.java:140)
Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing MappingNode
in 'reader', line 15, column 1:
server:
^
Duplicate key: spring
in 'reader', line 59, column 1:
^
at org.springframework.fig.structMapping(YamlProcessor.java:411)
at org.structor.struct(SafeConstructor.java:489)
at org.structObject(BaseConstructor.java:182)
at org.structDocument(BaseConstructor.java:141)
at org.Data(BaseConstructor.java:108)
at org.yaml.snakeyaml.(Yaml.java:471)
at org.springframework.fig.YamlProcessor.process(YamlProcessor.java:160)
at org.springframework.fig.YamlProcessor.process(YamlProcessor.java:138)
at org.v.YamlPropertySourceLoader$Processor.process(YamlPropertySourceLoader.java:101)
at org.v.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:58)
at org.v.PropertySourcesLoader.load(PropertySourcesLoader.java:127)
at org.t.config.ConfigFileApplicationListener$Loader.doLoadIntoGroup(ConfigFileApplicationListener.java:490)
at org.t.config.ConfigFileApplicationListener$Loader.loadIntoGroup(Confi
gFileApplicationListener.java:473)
... 21 common frames omitted
construct用法Process finished with exit code 1
注意图中有以spring开头的配置项,出现了两个spring,这是不符合yml配置语法的,所以启动报错。
解决⽅式:将yml配置⽂件修改为如下样⼦,再启动SpringBoot⼯程就不会报错了:
如果觉得本⽂对您有帮助,不妨扫描下⽅⼆维码打赏点,您的⿎励是我最⼤的动⼒:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论