Spring Boot Samples File未找到错误

时间:2014-06-25 13:48:34

标签: java spring spring-boot

我在关于spring boot项目的例子中。 我已经通过maven编译并创建了一个jar文件,但在运行尝试时出错。

https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-simple

项目文件夹: enter image description here

错误:

java -jar spring-boot-sample-simple-1.1.3.BUILD-SNAPSHOT.jar

014-06-25 09:10:00.653 ERROR 12028 --- [           main] o.s.boot.SpringApplication               : Application startup failed

ava.lang.IllegalStateException: Unable to load configuration files
       at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:158)
       at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.j
va:138)
       at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.j
va:131)
       at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:120)
       at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98)
       at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100)
       at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:59)
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:277)
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:944)
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:933)
       at sample.simple.SampleSimpleApplication.main(SampleSimpleApplication.java:46)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
       at java.lang.Thread.run(Unknown Source)
aused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
       at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
       at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:132)
       at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:121)
       at org.springframework.boot.env.PropertiesPropertySourceLoader.load(PropertiesPropertySourceLoader.java:44)
       at org.springframework.boot.env.PropertySourcesLoader.load(PropertySourcesLoader.java:126)
       at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadIntoGroup(ConfigFileApplicationListener.java:360)
       at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:349)
       at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:317)
       at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:155)
       ... 16 common frames omitted

2 个答案:

答案 0 :(得分:1)

当您尝试从jar文件运行应用程序时,有bug in Spring Boot 1.1.2导致Windows上的类加载出现问题。我建议回到1.1.1,直到它被修复。

答案 1 :(得分:0)

您错过了application.properties文件。使用Spring Boot,您可以将此文件放在与jar文件相同的级别,它将使用该文件。查看文档以获取更多信息link here